Giter Site home page Giter Site logo

ios-image-crop-view's Introduction

iOS-Image-Crop-View

A view allowing user to specify a rectangle area in an image. The user can drag the corner to resize it, move the entire bounding box, or use 2 fingers like a pinch gesture to move and resize the bounding box. The color and size of the dots on the corner can be customized.

Screenshot

alt text

Demo Video

How to Use

Very easy! It is created to be a drop-in component, so no static library, no extra dependencies. Just copy ImageCropView.h and ImageCropView.m to your project, and implement ImageCropViewControllerDelegate protocol.

Use it like UIImagePicker:

- (void)cropImage:(UIImage *)image{
	ImageCropViewController *controller = [[ImageCropViewController alloc] initWithImage:image];
	controller.delegate = self;
	[[self navigationController] pushViewController:controller animated:YES];
}
- (void)ImageCropViewController:(ImageCropViewController *)controller didFinishCroppingImage:(UIImage *)croppedImage{
   image = croppedImage;
   imageView.image = croppedImage;
   [[self navigationController] popViewControllerAnimated:YES];
}
- (void)ImageCropViewControllerDidCancel:(ImageCropViewController *)controller{
    imageView.image = image;
    [[self navigationController] popViewControllerAnimated:YES];
}

Optional Blurring

Using FXBlurView, you can now blur the parts of the image outside the crop area. This is not for blurring the final cropped image. Just set the blurredBackground property in the same place you set the delegate, like so:

controller.blurredBackground = YES;

Minimum Image Size

To set the minimum height and width of a cropped image, simply change the IMAGE_MIN_HEIGHT and IMAGE_MIN_WIDTH variables at the top of ImageCropView.m.

The project comes with a working example (as target ImageCropView) to demostrate the usage.

License

Copyright (C) 2012 Ming Yang

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ios-image-crop-view's People

Contributors

ajubbal avatar blashadow avatar im-jersh avatar michaellee1 avatar mnill avatar myang-git avatar sunshineo avatar tfrank64 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ios-image-crop-view's Issues

Croping Not Working smothely 2nd Time crop the same photo

Hello,

I have just implemented your library for cropping images and it's working superb when I edit the photo fist time but when I select the same photo second time to crop, the view controller appear and show the cropping screen but the box appear for selecting the image area is not move smoothly as it was working in First time cropping. Like when i try to drag the area it just stick to image bounds.

Just a couple of small fixes

Hi Mr Yang,

First, I'd like to congratulate you for your good work. This library has everything one needs to crop images in a natural way, in a simple and intuitive interface. I love it so much :-) But anyway, I've found a couple of things I had to fix before I had it working.

First of all, I found the alpha channel didn't set properly. I've changed the setShadeAlpha method in the ShadeView class, to be like this:

- (void)setShadeAlpha:(CGFloat)_alpha {
    shadeAlpha = _alpha;
    [self setNeedsDisplay];
}

Then, I found the size of the Control Points (the small balls on the corner) was being ignored too, and taking its default value even if we changed the property. To fix it, I added this line in the beggining of the setControlPointSize (in the ImageCropView class):

- (void)setControlPointSize:(CGFloat)_controlPointSize {
    controlPointSize = _controlPointSize;
    ....
}

And with this, I have it working nicely :-) Could you please look into it?

Again, thank you for your incredible work!

Swift Implementation

When instantiating the ImageCropViewController(image: myUIImage) it detects the initializer as the Delegate method ImageCropViewController(controller: UIViewController!, didFinishCroppingImage croppedImage: UIImage!) so it expects the initializer to provide the croppedImage argument

Boundries of image

When showing an image from the camera there is a part of the boundary not shown in the crop view. For normal pictures this is not noticeable since your area of interest is the center, however In some cases you are interested in items on the boundary and to me this is huge problem.

Memory Not Release after Cropping

Hello , I have used Image Crop View Classes in Base project after croping image and save image that release memory but in My Project it not release memory every time it will increase memory. I have tested in Iphone 4s. Can you please help me out anyone ?

-(void)OpenImageCropViewController:(UIImage *)imageObj
{
ImageCropViewController *controller = [[ImageCropViewController alloc] initWithImage:imageObj];
controller.delegate = self;
controller.blurredBackground = NO;
[[self navigationController] pushViewController:controller animated:NO];
}

pragma mark - IMAGECROP VIEWCONTROLLER DELEGATE METHOD

  • (void)ImageCropViewControllerSuccess:(ImageCropViewController *)controller didFinishCroppingImage:(UIImage *)croppedImage{

    //imgCurrDoc = croppedImage;

    NSLog(@"ViewControllers %@",[self navigationController].viewControllers);
    [[self navigationController] popViewControllerAnimated:YES];
    NSLog(@"AFTER ViewControllers %@",[self navigationController].viewControllers);
    [self createDocumentViewsWithImage:croppedImage];
    [self showBottomBar_DOCVC];

    controller.delegate = nil;
    controller = nil;
    }

  • (void)ImageCropViewControllerDidCancel:(ImageCropViewController *)controller{

    NSLog(@"ViewControllers %@",[self navigationController].viewControllers);
    [[self navigationController] popViewControllerAnimated:YES];
    NSLog(@"AFTER ViewControllers %@",[self navigationController].viewControllers);
    controller.delegate = nil;
    controller = nil;
    }

Support for portrait photos

Hi,
I try to use ImageCropViewController with a photo that I just taken with camera (using UIImagePickerController) in portrait mode.
It seems to has some problems, because the photo isn't displayed correctly.
Also, when I crop the image it appears rotated.

I have attached some screenshot to show the problem.
Thanks a lot!

  1. Take a photo in portrait mode
    1_takephoto
  2. Wrong layout in ImageCropViewController
    2_wronglayout
  3. Wrong orientation of cropped image
    3_wrongorientation

Issue with Square image

Hi, I have 614 by 614 image. When I try to tap on the image. it's automatically cropped and its not working well.

Getting Mach-O Linker Error

I copied ImageCropView.m , ImageCropView.h, FXBlurView into my Xcode project and tried to use but getting mach linker error as follows ;
< Undefined symbols for architecture x86_64:
"OBJC_CLASS$_ImageCropViewController", referenced from:
objc-class-ref in AllotmentViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation) >

How to solve this issue ?

rotate image

How we can rotate the image like every time i click onrotate, it will rotate by 90 degree like in whats app dp.?

FXBlurView will be available in Swift

Hello Team,
Are you guys creating the same code in swift also. Because i am trying to convert FXBlurView objective-c code into swift. In that, I am getting much problem.

Please let me know.
Thanks,
Manoj

Fixed crop size

Hi,

I wanted to ask if there is possible to set fixed size for cropping rectangle?

crop button doesn`t work

one mistake at line 70 in ViewController.m

 - (void)ImageCropViewController:

should be

- (void)ImageCropViewControllerSuccess:

Demo Project

Hello Ming,

When I was running your demo project, i found one of your methods in ViewController.m with the following name:

  • (void)ImageCropViewController:(ImageCropViewController *)controller didFinishCroppingImage:(UIImage *)croppedImage

This function is not part of the ImageCropViewControllerDelegate. I suspect that it should be the following code instead:

  • (void)ImageCropViewControllerSuccess:(ImageCropViewController *)controller didFinishCroppingImage:(UIImage *)croppedImage

I added a "Success" in your function name.

Am i missing something?

Thanks,

Jinhua Wang

Global variable conflicts

Hi,

I found the following variable declaration in ImageCropView.h

UIView* dragView;

This variable is declared as a GLOBAL VARIABLE and WILL CAUSE NAME CONFLICTS! (And it does caused name conflicts in my code)

Besides, I searched though the source code and it is nowhere used what so ever.

Thanks,

Jinhua Wang

protocol error

I've used three methods given in readme. Still There is error that protocol is not confirming . I am using this into swift. Thanks.

For Swfit

Can you help me to implement with swift version.
Thanks

ImageView and blurred image views can have different frames, causing weird 'zoom' effect

With some (large) photos, the imageView and blurredImageView versions of the image can have different frames, causing a weird "zoom in" effect where the blurred version of the image fits nicely but the underlying non-blurred version doesn't fit the screen.

Seen on iPhone 5c with photos (both landscape and portrait) taken on this device.

Solution is to set the image after setting the contentMode and clipsToBounds, as follows (within setImage method):

    /* prepare imageviews and their frame */
    self.shadeView.blurredImageView.contentMode = UIViewContentModeScaleAspectFill;
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    imageView.clipsToBounds = YES;
    self.shadeView.blurredImageView.clipsToBounds = YES;

    imageView.image = image;

Looks like otherwise the aspect fill scaling is not performed.

Refactor to code and class

Hi,
I think that the library need some refactor to the code.
For example:

  • Better class name with Apple convention (ex. XYZImageCropView)
  • Split the library into multiple files (one for each interface defined in ImageCropView.h file)
  • Remove demo.mov file from the repository (we can link it in YouTube or similar)

I can help you with some of this points if you need :)

Problem in context iOS 7

Hi!
First, thanks for this library! It's really amazing!

However, when I test the library I get this error in the console:

: CGContextSaveGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

There are errors for this states: CGContextRestoreGState, CGContextSaveGState, CGContextSetBlendMode, CGContextSetAlpha, CGContextTranslateCTM, CGContextScaleCTM, CGContextDrawImage.

Can you solve this problem?
Thanks a lot!

errors

/ImageCropView.m:324:126: No member named 'x' in 'CLLocationCoordinate2D'

/ImageCropView.m:324:172: No member named 'y' in 'CLLocationCoordinate2D'

Stretched Crop Area

I have this installed in a Swift 2.1 project. I have a view controller subclass and it's view's class is set to ImageCropView. Whenever I set the view.image with a landscape image everything seems to work just fine. However, when I set the view.image with a portrait image, the crop area stretches the cropped area to make it appear taller than the original.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.