我从字节数组创建位图图像并将其显示在 ImageView 中。这android:layout_width
and android:layout_height
ImageView 的设置为wrap_content,并且android:scaleType
设置为中心。但图像仍按屏幕尺寸缩放。
有没有办法以原始大小显示图像(就像直接使用 android:src 属性一样)?
CODE:
从字节数组创建位图:
private Bitmap decodeBitmap(byte[] data) {
return BitmapFactory.decodeByteArray(data, 0, data.length);
}
和 ImageView 的布局:
<ImageView
android:id="@+id/logo"
android:scaleType="centerInside"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
将图像设置为 ImageView:
mView.setImageBitmap(mBitmap);
请使用此代码
如果流来自资源
InputStream is = this.getResources().openRawResource(imageId1);
Bitmap originalBitmap = BitmapFactory.decodeStream(is);
ImageView myimage.setImageBitmap(originalBitmap);
myimage.setScaleType(ScaleType.MATRIX);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)