简体   繁体   English

从UIImage获取CGImage时出错

[英]Error in getting CGImage from UIImage

its work fine when we write: UIImage *img=[UIImage imageNamed:@"ImageName"]; 当我们编写时,它的工作正常:UIImage * img = [UIImage imageNamed:@“ ImageName”];

but when try to make uiimage from nsdata like:UIImage *img = [UIImage imageWithData:imageData]; 但是当尝试从nsdata制作uiimage时,例如:UIImage * img = [UIImage imageWithData:imageData]; now when we try to get cgimage from img in draw rect then it gives badAccess. 现在,当我们尝试从draw rect中的img获取cgimage时,它会给出badAccess。 if somebody know the exact way to write then please give me solution. 如果有人知道确切的书写方式,请给我解决方案。 i use CGImageRef sourceImageRef = [img CGImage]; 我使用CGImageRef sourceImageRef = [img CGImage]; in Draw Rect method of UIView. 在UIView的Draw Rect方法中。

尝试将UIImage转换为CGImage

CGImage imageRef = imageObject.CGImage

您应该像这样使用alloc init:

UIImage* myImage = [[UIImage alloc] initWithCGImage:myCGImage];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM