BitmapFactory.decodeByteArray在Android中返回null

问题描述:

在我的应用程序中,我将base64字符串转换为image.For为此我最初将base 64文件转换为字节数组,然后尝试转换为图像。 要转换为图片我使用下面的代码BitmapFactory.decodeByteArray在Android中返回null

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

,但我让我的形象,在空

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

请让我知道您的宝贵建议。

在此先感谢:)

+0

只是一个提示:留出一个空行之前和你的代码后,使正确的代码格式化 – WarrenFaith 2010-08-18 11:19:26

+0

@Remmyabhavan嗨,我遇到了同样的问题,你可以建议我 – Pragnani 2013-02-04 12:03:09

decodeByteArray不会将base 64编码转换为字节数组。你需要首先使用Base64到字节阵列转换器

+1

是的,我正在使用它将字节数组转换为位图images.But我得到空错误。我传递的图像数据是字节数组。 – Remmyabhavan 2010-08-18 12:16:55

我遇到了同样的问题。我解决它通过消除字符串的这一部分:

“数据:图像/ JPEG; BASE64,”