UIImageJPEGRepresentation和UIImagePNGRepresentation在iOS 13中返回nil [英] UIImageJPEGRepresentation and UIImagePNGRepresentation returns nil in iOS 13

查看:72
本文介绍了UIImageJPEGRepresentation和UIImagePNGRepresentation在iOS 13中返回nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我正在使用图像选择器在iPhone上选择图像.选择图像后,我将执行以下操作:

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);

在iOS 12.4.1及更低版本上,如果我选择PNG或JPEG图像,一切都可以正常工作.

On iOS 12.4.1 and below, everything works fine, if I pick either PNG or JPEG image.

在iOS 13上,JPG可以正常工作,但PNG不能.

On iOS 13, JPG works fine, but PNG does not.

如果我选择JPG:

data = UIImageJPEGRepresentation(image, 1.0); // works
data = UIImagePNGRepresentation(image); // works

但是,如果我选择了PNG:

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();

然后,当我这样做

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?

推荐答案

此问题已在beta 13.1中得以解决.

This issue is solved in beta 13.1.

这篇关于UIImageJPEGRepresentation和UIImagePNGRepresentation在iOS 13中返回nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆