2014-05-09 35 views
0

當我們編寫時它的工作很好: UIImage * img = [UIImage imageNamed:@「ImageName」];但是,當嘗試從nsdata,如:UIImage * img = [UIImage imageWithData:imageData]; 現在當我們試圖從img中獲取cgimage時,它會給badAccess。 如果有人知道確切的寫法,那麼請給我解決方案。 我使用CGImageRef sourceImageRef = [img CGImage];在UIView的Draw Rect方法中。從UIImage中獲取CGImage的錯誤

+0

提供一些更多的代碼 –

+0

http://stackoverflow.com/questions/17576054/cgimage -to-uiimage-doesnt-work – codercat

+0

http://stackoverflow.com/questions/12756295/uiimage-from-cgimageref – codercat

回答

0

您應該使用的alloc初始化,如:

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

試試這個轉換UIImageCGImage -

CGImage imageRef = imageObject.CGImage