BitmapFactory.decodeByteArray returns null in android

In my application, I convert a base64 string to an image. To do this, I initially converted the base 64 file to a byte array and later try to convert it to images. To convert to Pictures, I use the code below

File sdImageMainDirectory = new File("/data/data/com.ayansys.Base64trial"); FileOutputStream fileOutputStream = null; String nameFile="Images"; try { BitmapFactory.Options options=new BitmapFactory.Options(); options.inSampleSize = 5; options.inDither = true; options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0, imageData.length); fileOutputStream = new FileOutputStream( sdImageMainDirectory.toString() +"/" + nameFile + ".jpg"); BufferedOutputStream bos = new BufferedOutputStream( fileOutputStream); myImage.compress(CompressFormat.JPEG, quality, bos); bos.flush(); bos.close(); 

but i get my image as null in

 Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0, imageData.length); 

Please let me know your valuable suggestions.

Thanks in advance:)

+4
source share
2 answers

decodeByteArray will not convert 64 base encoding to a byte array. First you need to use Base64 to convert the byte array.

+2
source

I ran into this problem. I solved this by deleting this part of the line:

"Data: Image / JPEG; base64,"

+1
source

All Articles