0

Possible Duplicate:
What’s the easiest way to resize/optimize an image size with the iPhone SDK?

I want to change the reolution of image taken from camera to 320x320. Can any one please tell me how to do it.

I know how to take image from camera. So please tell me the rest (i.e) changing the reolution of image.

Thanks in advance

Community
  • 1
  • 1
surendher
  • 1,374
  • 3
  • 26
  • 52

2 Answers2

2

This is called in this post: https://stackoverflow.com/a/613380/1648976

+ (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.

This does a convert, not exactely to 320*320.. but you can twak the 0.6 to lower or higher.

If this is not what you want, please tell me more precisely

Community
  • 1
  • 1
David Raijmakers
  • 1,369
  • 1
  • 16
  • 40
0

1) Low-pass filter the original image and
2) decimate or
3) resample

If the original dimension is 640x320, it's enough to LP filter and then choose every other sample. That's decimation.

If the original dimension is e.g. 480x320, then one has to still LP filter and interpolate the pixel values for those pixels, that do not align exactly with the original pixels.

The LP filtering is crucial, as without it e.g. a very high resolution chessboard pattern will be re-sampled to noise or weird patterns, caused by an effect called 'frequency aliasing'.

Aki Suihkonen
  • 19,144
  • 1
  • 36
  • 57