Sim*_*iwi 0 console cgcontext ios
在我的应用程序中,我在控制台中收到以下错误:
May 1 22:06:59 iPhone-4S app[93660] <Error>: CGContextAddPath: invalid context 0x0
May 1 22:06:59 iPhone-4S app[93660] <Error>: clip: invalid context 0x0
Run Code Online (Sandbox Code Playgroud)
可以发生这种情况的唯一区域是使用以下两种方法之一来调整大小或向UIImage添加圆角边缘.以下是方法:
- (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize {
// Create a graphics image context
UIGraphicsBeginImageContext(newSize);
// Tell the old image to draw in this new context, with the desired
// new size
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
// Get the new image from the context
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
// End the context
UIGraphicsEndImageContext();
// Return the new image.
return newImage;
}
- (UIImage*)roundCorneredImage: (UIImage*)orig radius:(CGFloat) r {
UIGraphicsBeginImageContextWithOptions(orig.size, NO, 0);
[[UIBezierPath bezierPathWithRoundedRect:(CGRect){CGPointZero, orig.size}
cornerRadius:r] addClip];
[orig drawInRect:(CGRect){CGPointZero, orig.size}];
UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
Run Code Online (Sandbox Code Playgroud)
这两个方法都是从UIViewControllers中调用的,我很肯定UIImage不是nil.
这有什么理由发生吗?
谢谢!
| 归档时间: |
|
| 查看次数: |
1329 次 |
| 最近记录: |