c# - Strange behavior in xamarin android texture view app -


i´m working in mobile app (developed in xamarin android) able stream data camera, take picture , save in memory. app works there´s strange when deployed in different smartphones, showed in next pictures.

these screenshots of stream view when app installed in samsung (s7, s6, s7 edge) , alcatel (pop 2) smartphone looks supose be, going see, in others cellphones asus zefone go , sony xperia z1 image looks weird, if shape of objects changing :

app screenshots in asus , sony it´s difficult explain, changes appears when turn phone vertically mode (portrait) horizontally mode (landscape) this, rotation screen feature disabled. looks kind of distortion in image because (vertically mode),the objects looks more "extended", , (turning phone horizontally mode) looks shorter , fatter how looks originally.

this axml code of view:

<?xml version="1.0" encoding="utf-8"?> <framelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:layout_weight="1">     <textureview         android:id="@+id/textureview"         android:scaletype="fitxy"         android:layout_width="wrap_content"         android:layout_height="wrap_content" />     <button         android:id="@+id/takephotobutton"         android:layout_width="65dp"         android:layout_height="65dp"         android:layout_marginbottom="15dp"         android:layout_gravity="center|bottom"         android:background="@drawable/takephotobutton" />     <togglebutton         android:textoff=""         android:texton=""         android:checked="false"         android:layout_width="37dp"         android:layout_height="37dp"         android:layout_gravity="top|left"         android:layout_marginleft="25dp"         android:layout_margintop="25dp"         android:id="@+id/toggleflashbutton"         android:background="@drawable/flashbutton" /> </framelayout> 

this class:

namespace camerastream {     [activity(label = "camerastream", mainlauncher = true, icon = "@drawable/sendbutton", theme = "@android:style/theme.notitlebar")]     public class activity1 : activity, textureview.isurfacetexturelistener, ipicturecallback             {         android.hardware.camera _camera;          textureview _textureview;         button takepicturebtn;         togglebutton flashbtn;         bitmap userpicture;          protected override void oncreate(bundle bundle)         {             base.oncreate(bundle);             setcontentview(resource.layout.main);             _textureview = findviewbyid<textureview>(resource.id.textureview);             _textureview.surfacetexturelistener = this;             takepicturebtn = findviewbyid<button>(resource.id.takephotobutton);             takepicturebtn.click += takepicture_click;             flashbtn = findviewbyid<togglebutton>(resource.id.toggleflashbutton);             flashbtn.checkedchange += flash_click;         }         private void flash_click(object sender, compoundbutton.checkedchangeeventargs e)         {             globals g = globals.getinstance;             android.hardware.camera.parameters param = _camera.getparameters();             if (e.ischecked)             {                 g.setflash(true);                 flashbtn.setbackgroundresource(resource.drawable.noflashbutton);                 param.flashmode = android.hardware.camera.parameters.flashmodeon;                 _camera.setparameters(param);             }             else             {                 g.setflash(false);                 flashbtn.setbackgroundresource(resource.drawable.flashbutton);                 param.flashmode = android.hardware.camera.parameters.flashmodeoff;                 _camera.setparameters(param);             }         }         private void takepicture_click(object sender, eventargs e)         {             _camera.takepicture(null, null, this);                  }          public void onsurfacetextureavailable(android.graphics.surfacetexture surface, int w, int h)         {             globals g = globals.getinstance;             bool flash = g.getflash();             _camera = android.hardware.camera.open();             _camera.setdisplayorientation(90);             android.hardware.camera.parameters param = _camera.getparameters();             android.hardware.camera.size sizepicture = getbestpreviewsize(resources.displaymetrics.widthpixels, resources.displaymetrics.heightpixels);             param.zoom = 0;             param.focusmode = android.hardware.camera.parameters.focusmodecontinuouspicture;             param.setpicturesize(sizepicture.width, sizepicture.height);             param.flashmode = android.hardware.camera.parameters.flashmodeoff;             if (flash)                 param.flashmode = android.hardware.camera.parameters.flashmodeon;             else                 param.flashmode = android.hardware.camera.parameters.flashmodeoff;             _camera.setparameters(param);             try             {                 _camera.setpreviewtexture(surface);                 _camera.startpreview();             }             catch (java.io.ioexception ex)             {                 console.writeline(ex.message);             }         }         private android.hardware.camera.size getbestpreviewsize(int width, int height)         {             android.hardware.camera.size result = null;             android.hardware.camera.parameters p = _camera.getparameters();             ilist<android.hardware.camera.size> sizes = p.supportedpicturesizes;             foreach (android.hardware.camera.size size in sizes)             {                 if (size.width <= width && size.height <= height)                 {                     if (result == null)                     {                         result = size;                     }                     else                     {                         int resultarea = result.width * result.height;                         int newarea = size.width * size.height;                          if (newarea > resultarea)                         {                             result = size;                         }                     }                 }             }             return result;         }         public bool onsurfacetexturedestroyed(android.graphics.surfacetexture surface)         {             _camera.stoppreview();             _camera.release();              return true;         }         public void onsurfacetexturesizechanged(android.graphics.surfacetexture surface, int width, int height)         {             _camera.stoppreview();             _camera.setpreviewtexture(surface);             _camera.startpreview();         }         public void onsurfacetextureupdated(android.graphics.surfacetexture surface)         {         }         public void onpicturetaken(byte[] data, android.hardware.camera camera)         {             _camera.stoppreview();             bitmap picture = bitmapfactory.decodebytearray(data, 0, data.length);             userpicture = rotatebitmap(picture,90);             globals g = globals.getinstance;             g.setpicture(userpicture);             intent pictureactivity = new intent(this, typeof(pictureactivity));             this.startactivity(pictureactivity);             _camera.startpreview();         }         public static bitmap rotatebitmap(bitmap source, float angle)         {             matrix matrix = new matrix();             matrix.postrotate(angle);             return bitmap.createbitmap(source, 0, 0, source.width, source.height, matrix, true);         }     } } 

thanks help.


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -