Reputation: 8388
I have a view which has 3 subviews and all of the three subviews have uimageviews in uiscrolviews. So the imageviews can be scrolled or zoomed. The images are pretty large.
Now the total size of the view is 480X320 but I want to capture screen in bigger sizes e.g 960X640. But when I try to do it the image is stretched with pixels getting disturbed.
Is there a way to stretch a image which is large in size but displayed in small framed?
Thanks Pankaj
Upvotes: 0
Views: 586
Reputation: 1983
try this code it's working for me.
-(UIImage *)resizeImage:(UIImage *)image width:(int)width height:(int)height {
CGImageRef imageRef = [image CGImage];
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef);
//if (alphaInfo == kCGImageAlphaNone)
alphaInfo = kCGImageAlphaNoneSkipLast;
CGContextRef bitmap = CGBitmapContextCreate(NULL, width, height, CGImageGetBitsPerComponent(imageRef), 4 * width, CGImageGetColorSpace(imageRef), alphaInfo);
CGContextDrawImage(bitmap, CGRectMake(0, 0, width, height), imageRef);
CGImageRef ref = CGBitmapContextCreateImage(bitmap);
UIImage *result = [UIImage imageWithCGImage:ref];
CGContextRelease(bitmap);
CGImageRelease(ref);
return result;
}
Upvotes: 1