尝试下面的代码转换位图到bytearray和bytearray到位图,它将解决你的问题。

将位图转换为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)));

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐