Thuong Tran
Thuong Tran

Reputation: 139

How to resize image with small size from camera

Do you have anyway to resize image from camera to small size. I would like to resize image to 612 * 612 with disk size is less than 100KB. This will help me to show image on application faster.

Any advise ?

Upvotes: 0

Views: 291

Answers (2)

Vishal
Vishal

Reputation: 8256

Try with this:

-(UIImage *)imageWithImage:(UIImage *)imageToCompress scaledToSize:(CGSize)newSize {

    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
    [imageToCompress drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

Give your file name istead of getPath & call the above:

UIImage *img = [UIImage imageWithContentsOfFile:getPath];
UIImage *imageToPass = [self imageWithImage:img scaledToSize:CGSizeMake(612.0, 612.0)];

Upvotes: 0

Related Questions