[英]Encode UIImage in iOS7 and Decode it in Java (Base64)
I am trying to send a UIImage (taken from an iPhone's camera) to a Java Server and display it in a JFrame. 我正在尝试将UIImage(从iPhone的摄像头获取)发送到Java Server并将其显示在JFrame中。
It might have something to do with the Encoding Option as the String in Xcode and Eclipse are slightly different. 它可能与Encoding选项有关,因为Xcode和Eclipse中的String稍有不同。 ex.
例如 the xCode string has "+" for spaces, but in Eclipse, it has " " for spaces.
xCode字符串的空格带有“ +”,但是在Eclipse中,空格带有“”。
In Objective-C 在Objective-C中
UIImage *image = info[UIImagePickerControllerEditedImage];
NSData *imageData = UIImagePNGRepresentation([temp objectForKey:@"photo"]);
NSString *base64StringOfImage = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
I then send this NSString in json to Java 然后,我将此JSON中的NSString发送到Java
In Java 在Java中
byte[] imageBytes = Base64.decodeBase64(jsonPhoto.getString("photo"));
BufferedImage img = ImageIO.read(new ByteArrayInputStream(imageBytes));
I get this error on the BufferedImage img line: 我在BufferedImage img行上收到此错误:
javax.imageio.IIOException: Error reading PNG image data
If anyone can show me how to fix this, that would be great. 如果有人可以告诉我如何解决此问题,那将是很好的。
我想到了。
byte[] imageBytes = Base64.decodeBase64(jsonPhoto.getString("photo").replace(' ', '+'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.