Search code examples
iosobjective-ciphonecrop

how to crop image to image with offset and size?


I'm making an application that need to crop the image to another image. i want to crop the source Image ( like green rectangle) to destination image ( like white rectangle). I can get the size of source and destination image and the offset x and y . How can i got that crop image and save it to library? You can see the image attach here:

enter image description here

How can I crop to that image? and if you can please give me an example source code so much thanks for that


Solution

  • Check Below Code:

    -(UIImage *)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize
    {
    
    UIGraphicsBeginImageContext(newSize); 
    
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];  
    
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();   
    
    UIGraphicsEndImageContext();   
    
    return newImage;
    }
    

    Check below Links For reference:

    1. http://code4app.net/ios/Image-crop-demo/501e1f3f6803faea5d000000

    2. http://code4app.net/ios/Photo-Cropper-View-Controller/4f95519c06f6e7d870000000

    3. http://code4app.net/ios/Image-Cropper/4f8cc87f06f6e7d86c000000

    4. http://code4app.net/ios/Simple-Image-Editor-View/4ff2af4c6803fa381b000000

    Get sample code from here. Then you can customise your own.