图像的字节数组的ImageView [英] Byte array of image into imageview

查看:663
本文介绍了图像的字节数组的ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜查了一点,但不能得到它的一个明显的一瞥。如何设置图像的字节数组到一个ImageView的?我得到的字符串试图 BufferedImage的IMG = ImageIO.read(新ByteArrayInputStream的(字节)); 在Java中,但不能:(谁能帮助我对不起,如果这个问题?就像一个小白:)

I've searched a bit but cant get a clear glimpse of it. How can I set a byte array of an Image into an imageview? I got the string tried BufferedImage img = ImageIO.read(new ByteArrayInputStream(bytes)); as in java but not able to :( can anyone help me? sorry if the question was like a noob :)

推荐答案

尝试下面code为转换位图的字节数组,并B​​yteArray的位图,它会解决你的问题。

Try below code for convert bitmap to bytearray and bytearray to bitmap, it will solve your problem.

位图转换为ByteArray中: -

Convert Bitmap to 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的位图: -

Convert ByteArray to Bitmap:-

Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);

image.setImageBitmap(bmp);

这篇关于图像的字节数组的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆