42

少し調べてみましたが、はっきりとはわかりません。Image のバイト配列を に設定するにはどうすればよいImageViewですか? 私はこれで試しましたが、うまくいきませんでした。

BufferedImage img = ImageIO.read(new ByteArrayInputStream(bytes));
4

1 に答える 1

114

これは、 a を a に、 aをBitmapa に変換する方法です。ByteArrayByteArrayBitmap


Bitmap を ByteArray に変換します。

Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();

ByteArray をビットマップに変換します。

Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(Bitmap.createScaledBitmap(bmp, image.getWidth(), image.getHeight(), false));
于 2012-12-13T07:10:52.083 に答える