UIImageJPEGRepresentation 和 UIImagePNGRepresentation returns 无 iOS 13
UIImageJPEGRepresentation and UIImagePNGRepresentation returns nil in iOS 13
在我的应用程序中,我使用图像选择器 select iPhone 上的图像。图片被 select 编辑后,我会:
data = UIImageJPEGRepresentation(image, 1.0);
在 iOS 12.4.1 及更低版本上,如果我选择 PNG 或 JPEG 图片,一切正常。
在 iOS 13 上,JPG 可以正常工作,但 PNG 不能。
如果我选择 JPG:
data = UIImageJPEGRepresentation(image, 1.0); // works
data = UIImagePNGRepresentation(image); // works
但如果我选择 PNG:
data = UIImageJPEGRepresentation(image, 1.0); // data is nil
data = UIImagePNGRepresentation(image); // data is nil
我在这里查看了一些其他问题并尝试复制图像:
UIGraphicsBeginImageContext(image.size);
[image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
然后,当我这样做时
data = UIImageJPEGRepresentation(newImage, 1.0);
它不是零,但我得到了一个全白的图像。
有人对此有解决方法吗?
此问题已在 beta 13.1 中解决。
在我的应用程序中,我使用图像选择器 select iPhone 上的图像。图片被 select 编辑后,我会:
data = UIImageJPEGRepresentation(image, 1.0);
在 iOS 12.4.1 及更低版本上,如果我选择 PNG 或 JPEG 图片,一切正常。
在 iOS 13 上,JPG 可以正常工作,但 PNG 不能。
如果我选择 JPG:
data = UIImageJPEGRepresentation(image, 1.0); // works
data = UIImagePNGRepresentation(image); // works
但如果我选择 PNG:
data = UIImageJPEGRepresentation(image, 1.0); // data is nil
data = UIImagePNGRepresentation(image); // data is nil
我在这里查看了一些其他问题并尝试复制图像:
UIGraphicsBeginImageContext(image.size);
[image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
然后,当我这样做时
data = UIImageJPEGRepresentation(newImage, 1.0);
它不是零,但我得到了一个全白的图像。
有人对此有解决方法吗?
此问题已在 beta 13.1 中解决。