android图片转byte数组,android – 将图像的字节数组转换成imageview
尝试下面的代码转换位图到bytearray和bytearray到位图,它将解决你的问题。将位图转换为ByteArray: –Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);ByteArrayOutputStream stream = new ByteArrayOutputStream
尝试下面的代码转换位图到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)));
更多推荐
所有评论(0)