我正在尝试将UIImage(从iPhone的摄像头获取)发送到Java Server并将其显示在JFrame中。
它可能与Encoding选项有关,因为Xcode和Eclipse中的String稍有不同。例如 xCode字符串的空格带有“ +”,但是在Eclipse中,空格带有“”。
在Objective-C中
UIImage *image = info[UIImagePickerControllerEditedImage];
NSData *imageData = UIImagePNGRepresentation([temp objectForKey:@"photo"]);
NSString *base64StringOfImage = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
然后,我将此JSON中的NSString发送到Java
在Java中
byte[] imageBytes = Base64.decodeBase64(jsonPhoto.getString("photo"));
BufferedImage img = ImageIO.read(new ByteArrayInputStream(imageBytes));
我在BufferedImage img行上收到此错误:
javax.imageio.IIOException: Error reading PNG image data
如果有人可以告诉我如何解决此问题,那将是很好的。
我想到了。
byte[] imageBytes = Base64.decodeBase64(jsonPhoto.getString("photo").replace(' ', '+'));
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句