我需要使用 UIGraphicsBeginImageContextWithOptions 来捕获图像我的要求是从 -20 从原点开始捕获
任何帮助将不胜感激
我需要使用 UIGraphicsBeginImageContextWithOptions 来捕获图像我的要求是从 -20 从原点开始捕获
任何帮助将不胜感激
使用以下代码和 Import <QuartzCore/QuartzCore.h>
。您也可以在捕获图像后使用此代码。因此,您可以从中删除不必要的部分。
UIGraphicsBeginImageContext(self.view.frame.size);
//or
UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0.0);//this will also give you scaling option and more better for resolution.
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
CGImageRef ref = viewImage.CGImage;
CGRect myImageArea = CGRectMake (20, 20,
300, 100);// you define coordinates according your requirements.
CGImageRef mySubimage = CGImageCreateWithImageInRect (ref, myImageArea);
UIImage *yourfinalcapturedimage = [UIImage imageWithCGImage:mySubimage];// this will give you your required image.
希望对你有帮助..