我需要捕获一个视图,然后我必须裁剪该视图的某些部分。
我captureView
用来捕捉和cropView
裁剪部分。这是我的原始图像,这是我的输出图像。我想要清晰的图像。我试图将比例设为 0.0f,但它没有用。任何建议都可以接受。
- (UIImage *)captureView:(UIView *)view {
CGRect rect = [view bounds];
UIGraphicsBeginImageContextWithOptions(rect.size,NO,2.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *capturedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return capturedImage;
}
- (UIImage *) cropView:(UIImage *)originalImage frame:(CGRect)frame{
CGImageRef imageRef = CGImageCreateWithImageInRect([originalImage CGImage], frame);
UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return croppedImage;
}