Android:如何以原始尺寸显示图像

3
我从字节数组创建了一个位图图像,并在ImageView中显示它。ImageView的android:layout_width和android: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);

请添加您正在使用的代码。 - Dimitris Makris
1个回答

1
请使用以下代码,如果流来自资源:

InputStream is = this.getResources().openRawResource(imageId1); 
Bitmap originalBitmap = BitmapFactory.decodeStream(is);
ImageView myimage.setImageBitmap(originalBitmap); 
myimage.setScaleType(ScaleType.MATRIX); 

图片仍然按比例缩放以适应屏幕大小。我在这里使用setImageBitmap()将图像设置到ImageView中。 - John Smith
使用decodeBitmap()方法从字节数组创建图像。 - John Smith
为什么要使用解码流,像这样使用:originalBitmap = BitmapFactory.decodeStream(is)? - RajaReddy PolamReddy
好的,InputStream is = this.getResources().openRawResource(imageId1); originalBitmap = BitmapFactory.decodeStream(is);myimage.setImageBitmap(originalBitmap); myimage.setScaleType(ScaleType.MATRIX); - RajaReddy PolamReddy
图片来自哪里并不重要,流并非来自资源。 - John Smith
好的,抱歉,我不知道其他的事情,这意味着如果它不是来自资源,那么我就没有用处。如果它来自资源,我会很有用的。 - RajaReddy PolamReddy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接