Image Cropping Issue for Cropping an Image
I want to crop an image, and I have searched many libraries but have not found a perfect answer.
I want to crop an image using rectangle shape, which will have a fixed maximum height and width (300, 200), and a fixed minimum height and width (1.0, 1.0). The rectangle will also be movable, and can be resized to any size within the maximum and minimum dimensions.
我只部分理解你的问题,如果你正在寻找裁剪UIImage,请查看下面的代码:
//Pass the UIImage object and the varying rectangle you "outputrect"
- (UIImage *)cropImage:(UIImage *)image outPutRect:(CGRect) outputRect
{
CGImageRef takenCGImage = image.CGImage;
size_t width = CGImageGetWidth(takenCGImage);
size_t height = CGImageGetHeight(takenCGImage);
CGRect cropRect = CGRectMake(outputRect.origin.x * width, outputRect.origin.y * height,
outputRect.size.width * width, outputRect.size.height * height);
CGImageRef cropCGImage = CGImageCreateWithImageInRect(takenCGImage, cropRect);
image = [UIImage imageWithCGImage:cropCGImage scale:1 orientation:image.imageOrientation];
CGImageRelease(cropCGImage);
return image;
}
You can use TimOliver/TOCropViewController and change your cropping frame according to demand from TOCropViewController.m class,
1: Download full project from https://github.com/TimOliver/TOCropViewController.
2:Drag and drop TOCropViewController.h,TOCropViewController.m and class with other classes.
3:set ratio according to demand in TOCropViewController.m class with method [self setAspectRatioPreset:self.aspectRatioPreset animated:NO];
链接地址: http://www.djcxy.com/p/49970.html下一篇: 修剪图像的图像裁剪问题