2014-11-08 81 views
0

我需要使用此代碼base64編碼字符串轉換成圖像Im:目標C的base64字符串圖像不顯示

- (UIImage *)decodeBase64ToImage:(NSString *)strEncodeData { 
    NSData *data = [[NSData alloc]initWithBase64EncodedString:strEncodeData options:NSDataBase64DecodingIgnoreUnknownCharacters]; 
    return [UIImage imageWithData:data]; 
} 

//但只顯示一張圖片:(

IN的Android我使用此代碼:

public static Bitmap byteToImage(String byteArray) 
    { 
     Bitmap bitmap = null; 
     try { 
      byte[] decodedString = Base64.decode(byteArray,Base64.NO_WRAP); 
      InputStream inputStream = new ByteArrayInputStream(decodedString); 
      bitmap = BitmapFactory.decodeStream(inputStream); 
     } catch (Exception e) { 
      Log.e("byteToImage.EROOR.........", e.getMessage()); 
     } 
     return bitmap; 
    } 

什麼好主意或解決方案

+0

你的Android代碼是什麼? – tbaranes 2014-11-08 10:52:28

+0

我使用Nick Lockwood的Base64類別:https://github.com/nicklockwood/Base64 – Nick 2014-11-08 10:52:38

+0

您的代碼看起來不錯。你的base64圖像格式是否正確? – thedjnivek 2014-12-11 12:50:54

回答

0

這裏是我的Android代碼,它的工作。好 !

public static Bitmap byteToImage(String byteArray) 
    { 
     Bitmap bitmap = null; 
     try { 
      byte[] decodedString = Base64.decode(byteArray,Base64.NO_WRAP); 
      InputStream inputStream = new ByteArrayInputStream(decodedString); 
      bitmap = BitmapFactory.decodeStream(inputStream); 
     } catch (Exception e) { 
      Log.e("byteToImage.EROOR.........", e.getMessage()); 
     } 
     return bitmap; 
    } 
+0

請刪除此答案 – thedjnivek 2014-12-11 12:48:20