android - Image deforming when setting on ImageView -


in app i'm delevoping, user able photo gallery or take 1 directly camera, set profile picture.

then, photo shown in profile page, placed in way this:

enter image description here

my testing phone htc sensation kitkat 4.4.4. here pic shows ok, in personal device, galaxy s5 5.0, pic doesn't show well. fit's right entire space, appears deformed. if image in landscape, get's narrowed, , if in portrait, get's broad.

this code use proposal, in case, taking pic camera:

/*get's data onactivityresult*/ bitmap srcbmp = (bitmap) data.getextras().get("data");  bitmap landbmp = null; /*if square or portrait*/ if (srcbmp.getwidth() <= srcbmp.getheight()) {     landbmp = bitmap.createbitmap(         srcbmp,         0,         srcbmp.getheight()/4,         srcbmp.getwidth(),         srcbmp.getheight() /2     ); /*if on landscape*/ } else {     landbmp = srcbmp.copy(srcbmp.getconfig(), true); }  /*get screen dimensions*/ display display = getactivity().getwindowmanager().getdefaultdisplay(); point size = new point(); display.getsize(size); int screenwidth = size.x; int screenheight = size.y;  /*bitmap scaling*/ int picoriginalwidth = srcbmp.getwidth(); int picoriginalheight = srcbmp.getheight(); bitmap fullbitmap = bitmap.createscaledbitmap(landbmp, screenwidth, (originalheight*screenwidth)/originalwidth, true);  //after save pic on memory, works fine isn't relevant ... 

so, maybe of operations need correction fitted, or there better way this?

edit--

some things modificated in above text. problem not image doesn't fit imageview space. in fact, done. problem image getting resized , deformed.

using centercrop , adjustviewbounds job.

<imageview         android:layout_width="fill_parent"         android:layout_height="260dp"         android:id="@+id/picview"         android:src="@drawable/header_default_full"         android:scaletype="centercrop"         android:adjustviewbounds="true"         android:layout_alignparenttop="true" /> 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -