美文网首页iOS技术iOS 知识点
关于照片裁剪-PECrop

关于照片裁剪-PECrop

作者: Stark_Dylan | 来源:发表于2015-03-23 11:48 被阅读1428次

    首先 Git地址 PEPhotoCropEditor

    • 在做答疑君iOS端设计的时候, 我们会对碰到的照片进行一次裁剪, 然后把用户选中的一题扔到服务器上边。 然后去进一步操作。 因为项目开发比较急, 所以在Git上边找到了这个开源的组建库。

    PEPhotoCropEditor License MITLicense MIT

    VersionVersion
    PlatformPlatform
    Build StatusBuild Status
    AnalyticsAnalytics

    PEPhotoCropEditor is image cropping library for iOS, similar to the Photos.app UI.

    <img src="https://raw.github.com/kishikawakatsumi/PEPhotoCropEditor/master/Screenshots/ss01.png" alt="ScreenShot 1" width="280px" style="width: 280px;" /> <a href="https://vimeo.com/66661806"><img src="https://raw2.github.com/kishikawakatsumi/PEPhotoCropEditor/master/Screenshots/movie03.gif" style="width: 242px; height: 476px;" alt="Movie 1" /></a>

    Features

    • Both iPhone/iPad available
    • Works fine any device orientations
    • Support pinch gesture to zoom
    • Support rotation gesture

    System requirements

    • iOS 5.0 or higher

    Installation

    CocoaPods

    pod 'PEPhotoCropEditor'

    Usage

    Use view controller component

     PECropViewController *controller = [[PECropViewController alloc] init];
     controller.delegate = self;
     controller.image = self.imageView.image;
     
     UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
     [self presentViewController:navigationController animated:YES completion:NULL];
    

    Or use the crop view directly

    self.cropView = [[PECropView alloc] initWithFrame:contentView.bounds];
    [self.view addSubview:self.cropView];
    

    Get the cropped image

    delegate method

    - (void)cropViewController:(PECropViewController *)controller didFinishCroppingImage:(UIImage *)croppedImage
    {
        [controller dismissViewControllerAnimated:YES completion:NULL];
        self.imageView.image = croppedImage;
    }
    

    retrieve from view directly

    UIImage *croppedImage = self.cropView.croppedImage;
    

    Keep crop aspect ratio while resizing

    controller.keepingCropAspectRatio = YES;
    
    self.cropView.keepingCropAspectRatio = YES;
    

    Specify crop rect by image size based

    // e.g.) Cropping center square
    CGFloat width = image.size.width;
    CGFloat height = image.size.height;
    CGFloat length = MIN(width, height);
    controller.imageCropRect = CGRectMake((width - length) / 2,
                                          (height - length) / 2,
                                          length,
                                          length);
    
    // e.g.) Cropping center square
    CGFloat width = image.size.width;
    CGFloat height = image.size.height;
    CGFloat length = MIN(width, height);
    self.cropView.imageCropRect = CGRectMake((width - length) / 2,
                                             (height - length) / 2,
                                             length,
                                             length);
    

    Reset back crop rect to original image size and rotation

    [controller resetCropRect];
    
    [self.cropView resetCropRect];
    

    License

    PEPhotoCropEditor is available under the MIT license. See the LICENSE file for more info.

    相关文章

      网友评论

        本文标题:关于照片裁剪-PECrop

        本文链接:https://www.haomeiwen.com/subject/uvkgxttx.html