我搜索了一下但是没有得到一个清晰的了解。如何将图像的字节数组设置为 ImageView
?我尝试了这个方法,但它没有起作用。
BufferedImage img = ImageIO.read(new ByteArrayInputStream(bytes));
我搜索了一下但是没有得到一个清晰的了解。如何将图像的字节数组设置为 ImageView
?我尝试了这个方法,但它没有起作用。
BufferedImage img = ImageIO.read(new ByteArrayInputStream(bytes));
以下是将 Bitmap
转换为 ByteArray
,以及将 ByteArray
转换为 Bitmap
的方法:
将 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:
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));