I am trying to send a UIImage (taken from an iPhone's camera) to a Java Server and display it in a JFrame.
It might have something to do with the Encoding Option as the String in Xcode and Eclipse are slightly different. ex. the xCode string has "+" for spaces, but in Eclipse, it has " " for spaces.
In 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
In Java
byte[] imageBytes = Base64.decodeBase64(jsonPhoto.getString("photo"));
BufferedImage img = ImageIO.read(new ByteArrayInputStream(imageBytes));
I get this error on the BufferedImage img line:
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(' ', '+'));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.