heitorfr/ios-image-editor
关于
用于裁剪图像的 iOS View Controller。它是 UIImagePickerController 编辑器的替代方案,并提供扩展功能。
设计与媒体可以做什么
- Full image resolution
- Unlimited pan, zoom and rotation
- Zoom and rotation centered on touch area
- Double tap to reset
实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文iOS Image Editor
A iOS View Controller for image cropping. An alternative to the UIImagePickerController editor with extended features and flexibility. Drop me a line if your're using this on your apps, I would like to know.
Features
- Full image resolution
- Unlimited pan, zoom and rotation
- Zoom and rotation centered on touch area
- Double tap to reset
- Handles EXIF orientations
- Plug-in your own interface
Usage
HFImageEditorViewController *imageEditor = [[HFImageEditorViewController alloc] initWithNibName:@"DemoImageEditor" bundle:nil];
imageEditor.sourceImage = image;
imageEditor.doneCallback = ^(UIImage *editedImage, BOOL canceled){
...
}
Configuration Properties
sourceImage
The full resolution UIImage to crop
previewImage
For images larger than 1024 wide or 1024 height, the image editor will create a preview image before the view is shown. If a preview is already available you can get a faster transition by setting the preview propety. For instance, if the image was fetched using the UIImagePickerController:
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
[self.library assetForURL:assetURL resultBlock:^(ALAsset *asset) {
UIImage *preview = [UIImage imageWithCGImage:[asset aspectRatioThumbnail]];
HFImageEditorViewController *imageEditor = [[HFImageEditorViewController alloc]
initWithNibName:@"DemoImageEditor" bundle:nil];
self.imageEditor.sourceImage = image;
self.imageEditor.previewImage = preview;
...
} failureBlock:^(NSError *error) {
NSLog(@"Failed to get asset from library");
}];
doneCallback
The callback block called when the image editor completes. Returns the cropped image and a BOOL that specifies if completion results from a done or cancel actions.
cropSize
A CGSize specifying the width and height of the crop area in screen coordinates. NOTE: Currently HFImageEditorViewController is expecting cropSize to be set only after its view and the frameView outlet have been set. If you subclass HFImageEditorViewController you can do it in viewDidLoad; if not, you should set it after adding HFImageEditorViewController to the view controller hierarchy.
cropRect
A CGRect specifying the crop area in screen coordinates. Use instead of cropSize if the crop area is not centered. NOTE: Currently HFImageEditorViewController is expecting cropRect to be set only after its view and the frameView outlet have been set. If you subclass HFImageEditorViewController you can do it in viewDidLoad; if not, you should set it after adding HFImageEditorViewController to the view controller hierarchy.
outputWidth
The width of the cropped image. If not defined, the width of the source image is assumed.
minimumScale, maximumScale
The bounds for image scaling. If not defined, image zoom is unlimited.
checkBounds
Set to true to bound the image transform so that you dont' get a black backround on the resulting image.
panEnabled, rotateEnabled, scaleEnabled, tapToResetEnabled
BOOL property to enable/disable specific gestures
Output Properties
####cropBoundsInSourceImage Returns a CGRect representing the current crop rectangle in the source image coordinates. Source image coordinates have the origin at the bottom left of the image. Note that, if rotation has been applyed, then cropBoundsInSourceImage represents the bounding box of the rotated crop rectangle.
Interface
Create your own xib for a custom user interface.
- Set
HFImageEditorViewController(or subclass) as the file owner - Set the
frameViewoutlet. This view must implement theHFImageEditorFrameprotocol. It must be transparent in the crop area, the image will show behind. A default implementation ImageEditorFrameView is provided - Connect interface elements to the available actions:
done,reset,resetAnimatedandcancel.
The demo app also shows how extended controlls can be implemented: three buttons are used for square, portrait and landscape crop.
Use the subclassing hooks (startTransformHook, endTransformHook) if you need to update the interface during image processing (to diable UI controls, for instance).
License
ios-image-editor is available under the MIT license. See the LICENSE file for more info.
探索相关项目
加载中…