私はAndroidを初めて使用します。SDカードから画像を読み込み、画像ビューコントロールを使用してビットマップ画像として表示するサンプルアプリケーションを1つ開発しました。今、私はバイト配列からbmpをロードするようにアプリケーションを変更したいのですが、生の画像、幅、高さを持っていますが、これのサンプルはありますか?
質問する
2916 次
3 に答える
5
以下のコードを使用してバイト配列をビットマップに変換し、このビットマップをImageViewに表示します。
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(bmp);
詳細については、以下のSOリンクを参照してください。
于 2012-09-18T05:22:39.080 に答える
1
使えると思いますBitmapFactory
。
public static Bitmap decodeByteArray (byte[] data, int offset, int length)
詳細については、こちらをご覧ください
于 2012-09-18T03:50:23.953 に答える
0
画像がDrawableフォルダにある場合は、このコードを試してください
Drawable drawable= getResources().getDrawable(R.drawable.yourimage);
//Type cast to BitmapDrawable
Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
//Write a compressed version of the bitmap to the specified outputstream via compress method.
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
byte[] buffer = stream.toByteArray();
于 2012-09-18T04:06:11.880 に答える