Reputation: 111
I create an bitmap image from byte array and display it in an ImageView. The android:layout_width
and android:layout_height
of the ImageView are set to wrap_content, and the android:scaleType
is set to center. But the image is still scaled to the screen size.
Is there a way to display the image at its original size (just like using the android:src attribute directly)?
CODE:
create bitmap from byte array:
private Bitmap decodeBitmap(byte[] data) {
return BitmapFactory.decodeByteArray(data, 0, data.length);
}
and layout of the ImageView:
<ImageView
android:id="@+id/logo"
android:scaleType="centerInside"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
set image to ImageView:
mView.setImageBitmap(mBitmap);
Upvotes: 3
Views: 5662
Reputation: 22493
Please use this code if the stream is from resource
InputStream is = this.getResources().openRawResource(imageId1);
Bitmap originalBitmap = BitmapFactory.decodeStream(is);
ImageView myimage.setImageBitmap(originalBitmap);
myimage.setScaleType(ScaleType.MATRIX);
Upvotes: 1