MayurCM
MayurCM

Reputation: 701

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

Upvotes: 0

Views: 261

Answers (2)

Daulat Bachhav
Daulat Bachhav

Reputation: 356

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

Upvotes: 1

Biraj Zalavadia
Biraj Zalavadia

Reputation: 28484

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

Upvotes: 0

Related Questions