java - Android - Assigning Bitmap to ImageView changes size -
my application takes photo camera of smartphone. after capturing photo want assign photo imageview. size of imageview changes.
protected void onactivityresult(int requestcode, int resultcode, intent data) { if (requestcode == capture_image_activity_request_code && resultcode == activity.result_ok) { contentresolver cr = getcontentresolver(); bitmap bitmap = null; bitmap scaledbitmap = null; inputstream in = null; image image = this.getactualimage(); try { in = cr.openinputstream(this.imageuri); bitmapfactory.options o = new bitmapfactory.options(); o.insamplesize = 1; bitmap = bitmapfactory.decodestream(in, null, o); imageview view = null; view = (imageview) findviewbyid(r.id.img_face1); int height = view.getheight(); int width = view.getwidth(); log.i(tag, "scale operation dimenions - width: " + width + ", height: " + height); scaledbitmap = bitmap.createscaledbitmap(bitmap, width, height, true); view.setimagebitmap(scaledbitmap); system.gc(); in.close(); } catch (exception e) { log.e("camera", e.tostring()); } my layout xml looks follows:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/screen_capture_face2" style="@style/linearlayoutvertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:weightsum="2" > <imageview android:id="@+id/img_face1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:adjustviewbounds="true" android:contentdescription="@string/desc_dummy_face" android:src="@drawable/dummy_face" /> <imageview android:id="@+id/img_face2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:adjustviewbounds="true" android:contentdescription="@string/desc_dummy_face" android:src="@drawable/dummy_face" /> </linearlayout> after assign bitmap imageview img_face1 size changes. why happen? missing? new android , maybe little mistake.
thanks bye
first of all, setting adjustviewbounds true. reference says:
set true if want imageview adjust bounds preserve aspect ratio of drawable.
you try removing it, , additionally add scaletype="fitcenter" option image resized instead of image view. want change wrap_content values layout attributes, make view big enough show entire content.
Comments
Post a Comment