I am working on an app which is fully dependent on images. I have images like 320*480 now I want those same images with 768*1024 dimension. I can get it by UI designer and place in my bundle but my application is for universal app so I needed to include same image for iPhone retina, iPad, iPad retina. If I am using multiple images my IPA size goes increase (ex: if an image with 320*480 having 200KB now if I again adding 768*1024 the size of my IPA will increased to at least 200KB).
Idea: I am placing only 320*480 images and planning to create 768*1024 images programmatically which means only one set of images I am using in my bundle.
Work done: By looking some blogs I found that using below code we can create required image sizes.
- (UIImage *)scale:(UIImage *)image toSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
UIImage *smallImage=[UIImage imageNamed:@"1.png"];
UIImage *bigImage=[self scale:smallImage toSize:CGSizeMake(768, 1024)];
[UIImageJPEGRepresentation(bigImage,2.0) writeToFile:[[self applicationDocumentsDirectory]stringByAppendingPathComponent:@"upload.png"] atomically:YES];
Problem: Above code works cool and getting the expected size of images but only problem is I am getting pixel distortion on the end image.
Question: Is there any good or efficient solution to get different dimensions with out distortion image from the small image or I need to get all my images from the UI designer. If we have normal Image can we create same image for retina display?
Is there a better solution?