tags:

views:

24

answers:

0

Hello,

I am working on an application that allows a user to pick a photo from their camera roll or take a picture. From the picture, I need to increase the size to be 1050x670 and keep the quality of the image. I am able to increase the image, but the picture comes out very pixelated when I send it through email.

In the app, I will be sending the enlarged image to a server for additional processing.

Any help would be appreciated. Here is some of code:

CGSize newSize = CGSizeMake(1050, 670);

CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height));

CGImageRef imageRef = [userImageView.image CGImage];

// Compute the bytes per row of the new image
size_t bytesPerRow = CGImageGetBitsPerPixel(imageRef) / CGImageGetBitsPerComponent(imageRef) * newRect.size.width;
bytesPerRow = 26 * 1050;//(bytesPerRow + 15) & ~15;  

CGContextRef bitmap = CGBitmapContextCreate(NULL,
newRect.size.width,
newRect.size.height,
8,
bytesPerRow,
CGImageGetColorSpace(imageRef),
kCGImageAlphaNoneSkipLast);

CGContextSetInterpolationQuality(bitmap, kCGInterpolationHigh);

// Draw into the context; this scales the image
CGContextDrawImage(bitmap, newRect, imageRef);

// Get the resized image from the context and a UIImage
CGImageRef resizedImageRef = CGBitmapContextCreateImage(bitmap);
UIImage *resizedImage = [UIImage imageWithCGImage:resizedImageRef];

// Clean up
CGContextRelease(bitmap);
CGImageRelease(resizedImageRef);

UIImageWriteToSavedPhotosAlbum(resizedImage, nil, nil, nil);

return resizedImage;

Thanks.