我从字节数组创建位图图像并将其显示在 ImageView 中。ImageView的android:layout_width
andandroid:layout_height
设置为 wrap_content,android:scaleType
设置为 center。但是图像仍然缩放到屏幕尺寸。
有没有办法以原始大小显示图像(就像直接使用 android:src 属性一样)?
代码:
从字节数组创建位图:
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);