问题
In my app I'm using the image picker to select an image on an iPhone. After the image was selected, I do:
data = UIImageJPEGRepresentation(image, 1.0);
On iOS 12.4.1 and below, everything works fine, if I pick either PNG or JPEG image.
On iOS 13, JPG works fine, but PNG does not.
If I pick a JPG:
data = UIImageJPEGRepresentation(image, 1.0); // works
data = UIImagePNGRepresentation(image); // works
But if I pick a PNG:
data = UIImageJPEGRepresentation(image, 1.0); // data is nil
data = UIImagePNGRepresentation(image); // data is nil
I looked at some other questions here and tried copying the image:
UIGraphicsBeginImageContext(image.size);
[image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Then, when I do
data = UIImageJPEGRepresentation(newImage, 1.0);
it's not nil, but I get an all-white image.
Does anyone have an idea for a workaround for this?
回答1:
This issue is solved in beta 13.1.
来源:https://stackoverflow.com/questions/58012911/uiimagejpegrepresentation-and-uiimagepngrepresentation-returns-nil-in-ios-13