在Swift Base64编码不会在Android中解码

我有一个Android应用程序,它使用Base64编码图像,编码的string存储在服务器上。 我现在正在为同一个应用程序的iOS客户端,并正在努力使其编码图像以相同的方式在Android端编码的图像将在Swift iOS中解码,但在Swift中编码的图像不会解码在Android中,或在这里http:/ / /www.freeformatter.com/base64-encoder.html (生成的文件不是有效的图像)

在iOS中编码的图像将在iOS中解码

在Android中,我正在使用以下编码和解码

public static String encodeBitmap(Bitmap bitmap) { Bitmap immagex = bitmap; ByteArrayOutputStream baos = new ByteArrayOutputStream(); immagex.compress(Bitmap.CompressFormat.PNG, 100, baos); byte[] b = baos.toByteArray(); String imageEncoded = Base64.encodeToString(b, Base64.DEFAULT); return imageEncoded; } public static Bitmap decodeBitmap(String encodedString) { byte[] decodedByte = Base64.decode(encodedString, Base64.DEFAULT); Bitmap b = BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length); return b; } 

以下在iOS端

 static func decodeImage(str: String) -> UIImage?{ if let decodedData = NSData(base64EncodedString: str, options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters){ var iconValue:UIImage? = UIImage(data: decodedData) return iconValue } return nil } static func encodeImage(image: UIImage) -> String{ var imageData = UIImagePNGRepresentation(image) let base64 = imageData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding76CharacterLineLength) return base64 } 

}

我愿意改变任何一个客户,使其工作

例如:以此图像为例https://pbs.twimg.com/profile_images/522909800191901697/FHCGSQg0.png

在Android上,它编码为http://pastebin.com/D41Ldjis

并在iOS上http://pastebin.com/fEUZSJvF

iOS有一个更大的字符数

提供的Base64来自不同的PNG编码。 标头不同,Android有一个“sBIT”块,iOS有一个“sRGB”块。

所以这个问题不是Base64,而是两个系统的代表。

解码的部分

安卓:
APNG

IHDR††≠zsBIT€·O2‡ÑIDAT

iOS版:
APNG

IHDR»»≠XÆûsRGBÆŒÈiDOTd(ddp`ùıºIDAT