[英]issue displaying byte array to bitmap to fetch an image in android
我在将字节数组转换为位图时遇到问题。 现在,我要实现的是将图像作为字节数组获取,并尝试转换为位图,以便可以显示图像。 但是在我的位图输出中运行下面的代码后,我得到了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);
我在Google上搜索了很多,发现此代码适用于every1。 可以请别人告诉我我做错了什么。
提前致谢
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);
试试这个
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.