0

In my app I can take a photo from the camera and display it in an imageview, but what I want to be able to do is rescale/resize the resolution of the image so it's not as big and does not take up so much memory in the app.

Here is the code I use for displaying the image in the imageview:

image = [info objectForKey:UIImagePickerControllerOriginalImage];
[ImageView1 setImage:image];    // "ImageView1" name of any UImageView.
[self dismissViewControllerAnimated:YES completion:NULL];

I want the image scaled down as the image can also be sent via email, so it must be nice and small.

Zero Piraeus
  • 56,143
  • 27
  • 150
  • 160
Azabella
  • 837
  • 2
  • 10
  • 18

1 Answers1

0

You can try this code:

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

 return newImage;
}

As far as storage of the image, the fastest image format to use with the iPhone is PNG, because it has optimizations for that format. However, if you want to store these images as JPEGs, you can take your UIImage and do the following:

NSData *dataForJPEGFile = UIImageJPEGRepresentation(theImage, 0.6);

This creates an NSData instance containing the raw bytes for a JPEG image at a 60% quality setting. The contents of that NSData instance can then be written to disk or cached in memory.

You can refer this link also: UIImage: Resize, then Crop

Hope this will helps you.

Community
  • 1
  • 1
iDeveloper
  • 223
  • 2
  • 5