简体   繁体   中英

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 .

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. 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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