-1

I have two questions regarding Image. 1 ) When user selects an image then some times the image is size is very large, when image is captured from IPhone 6 or 6S then the image size is 15MB to 20MB, that takes a long time to be uploaded to the server. How can i crop or resize the image to be small and to in enough size that it can be in good resolution

2) When showing the images to user, some images are landscapes and some are portraits, when images are in high resolution then it is difficult to show those on the screen . I want a algorithm which crops the image, For example when the image is landscape then it means we have to crop some size from left and right and when the image is portrait then it means that we have to crop the image portion from top and bottom

How can i do these two things ??

Thanks

2 Answers2

0

This is what i use in my app for resize image :

+ (UIImage *)resizeImage:(UIImage *)image {
    CGSize newSize = CGSizeMake(800, 800);
    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

Maybe convert the image in jpeg for optimized the size (UIImageJPEGRepresentation)

For the second point, why not use the aspectfill contentmode of UIImageView ?

ejanowski
  • 538
  • 5
  • 20
0

You can use the following library "https://github.com/ruslanskorb/RSKImageCropper" to implement image cropping.

Akshay Agrawal
  • 217
  • 3
  • 12