3

バイト配列からビットマップ イメージを作成し、ImageView に表示します。ImageViewのandroid:layout_widthandroid:layout_heightは wrap_content に設定され、は center にandroid:scaleType設定されます。ただし、画像は引き続き画面サイズにスケーリングされます。

画像を元のサイズで表示する方法はありますか (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);
4

1 に答える 1

1

ストリームがリソースからのものである場合は、このコードを使用してください

InputStream is = this.getResources().openRawResource(imageId1); 
Bitmap originalBitmap = BitmapFactory.decodeStream(is);
ImageView myimage.setImageBitmap(originalBitmap); 
myimage.setScaleType(ScaleType.MATRIX); 
于 2011-10-24T08:58:31.490 に答える