UIImageJPEGRepresentation and UIImagePNGRepresentation returns nil in iOS 13

馋奶兔 提交于 2021-01-28 07:31:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!