I am getting the list of contacts from the Address book in that some contacts have images which are taken with camera they are very huge in size.I am displaying the contacts along with their images in a 3x3 rows and columns format.The problem is due to huge size of the images its taking time to load the images.Can anyone suggest me how to Compress them. I tried to compress them in a way:
if ([imageData length] > 0)
{
int len = [imageData length];
if(len > 9000)
{
UIImage *theImage = [UIImage imageWithData:imageData];
imageData = UIImageJPEGRepresentation(theImage,0.5);
printf("\n image data length in condition...%d",[imageData length]);
imageViewL.image = [UIImage imageWithData:imageData];
}
else
{
imageViewL.image = [UIImage imageWithData:imageData];
}
}
Eventhough its taking time to load.
Anyone's help will be much appreciated.
Thanks to all, Monish.
You can resize the image captured by the iphone camera by using the following lines of code
-(UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)newSize
{
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
and then call this method like this
UIImage *image = [self scaleImage:your image toSize:CGSizeMake(320.0,480.0)];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With