0

有没有一种简单的方法可以选择 UIImage 实例的一个区域,然后从中创建一个新图像?我尝试使用平移手势识别器来获取用户选择的坐标。但是有了这个选项,现在有可见的反馈,我还必须转换坐标。是否有一个不错的插件或最佳实践来做到这一点?

4

2 回答 2

0

尝试这个:

   UIGraphicsBeginImageContext(self.view.bounds.size);
// retrieve the current graphics context
   CGContextRef context = UIGraphicsGetCurrentContext();
// render view into context
   [self.view.layer renderInContext:context];
// create image from context
   UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
   image=[self cropImage:image];
   UIGraphicsEndImageContext();

   - (UIImage *)cropImage:(UIImage *)oldImage {
       CGSize imageSize = oldImage.size;
       UIGraphicsBeginImageContextWithOptions(CGSizeMake( imageSize.width,imageSize.height - 150),NO,0.); //set your height and width
          [oldImage drawAtPoint:CGPointMake( 0, -80) blendMode:kCGBlendModeCopy alpha:1.];
          UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext();
          UIGraphicsEndImageContext();
          return croppedImage;
   }
于 2013-04-04T13:27:12.187 回答
0

像这样:

CGImageRef imageRef = CGImageCreateWithImageInRect([bigImage CGImage], cropRect);
UIImage *croppedImage = [UIImage imageWithCGImage:imageRef]; 
CGImageRelease(imageRef);
于 2013-04-04T13:28:42.307 回答