简体   繁体   English

问题显示将字节数组显示为位图以获取android中的图像

[英]issue displaying byte array to bitmap to fetch an image in android

I'm having problem converting byte array to bitmap. 我在将字节数组转换为位图时遇到问题。 Now what I'm trying to achieve is I'm getting image as a byte array and trying to convert into bitmap so that I can display the image. 现在,我要实现的是将图像作为字节数组获取,并尝试转换为位图,以便可以显示图像。 but after running my below code in my bitmap output i'm getting Null value . 但是在我的位图输出中运行下面的代码后,我得到了Null值

String t= "byte array of the image";
byte[] temp = t.getBytes() ;
Bitmap bmp = BitmapFactory.decodeByteArray(temp, 0, temp.length);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
System.out.println("bitmap output"+bmp);

I have googled a lot and found this code works for every1. 我在Google上搜索了很多,发现此代码适用于every1。 can please someone tell me where I'm doing wrong. 可以请别人告诉我我做错了什么。

Thanks in advance 提前致谢

In my case this is working

String result = "here imge;

if (result != "") {
byte[] bloc = Base64.decode(result); 
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 8; 
Bitmap b = BitmapFactory.decodeByteArray(bloc, 0, bloc.length);

Try this way 试试这个

String t= "byte array of the image";

byte[] temp = Base64.decode(t, Base64.NO_WRAP); //UPDATE HERE

Bitmap bmp = BitmapFactory.decodeByteArray(temp, 0, temp.length);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
System.out.println("bitmap output"+bmp);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM