【问题标题】:Image Cropping from Gallery从图库中裁剪图像
【发布时间】:2013-06-10 12:03:06
【问题描述】:

我想从图库中裁剪选定的图像(以编程方式)。我做了很多研究,并让 [tutor](http://iosdevelopertips.com/graphics/how-to-crop-an-image.html) 经历了这个。仍然困惑是否可以使用 UIImagePickerController 或 UIImageView 来完成图像的裁剪。我没有得到从哪里开始或如何开始?请向我推荐正确的方法。

【问题讨论】:

    标签: ios objective-c uiimageview uiimagepickercontroller


    【解决方案1】:

    回答: CGImage Reference

    1) 从现有图像的中间创建一个代表裁剪图像的矩形:

    CGRect rect = CGRectMake(size.width / 4, size.height / 4 , 
        (size.width / 2), (size.height / 2));
    

    2) 从原始图像数据创建位图图像,使用矩形指定所需的裁剪区域:

    CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect);
    UIImage *img = [UIImage imageWithCGImage:imageRef]; 
    CGImageRelease(imageRef);
    

    3) 从位图数据创建并显示新图像:

    imageView = [[UIImageView alloc] initWithImage:img];
    

    有用的链接:

    1) Working with UIGestureRecognizers.

    2) Cropping and Resizing Images from Camera in iOS and Objective-C.

    祝你好运!!!

    【讨论】:

      猜你喜欢
      • 2016-02-17
      • 2020-12-21
      • 2013-03-22
      • 2017-05-22
      • 1970-01-01
      • 2015-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多