2010-06-28 64 views
0

我正在研究一个应用程序,允许用户从相机胶卷中选取照片或拍照。从图片中,我需要将尺寸增加到1050x670并保持图像的质量。我能够增加图像,但是当我通过电子邮件发送图片时,图片非常像素化。iPhone - 放大图像,保持质量

在应用程序中,我将发送放大的图像到服务器进行额外的处理。

任何帮助,将不胜感激。以下是一些代码:

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; 
+3

你期望什么?缩放图像不会为图像添加任何细节,因此它会变得模糊或像素化... – Lucero 2010-06-28 22:38:41

+0

您不能为图像添加额外的像素(或细节),但不以 – 2010-06-28 22:54:05

+0

开头为什么你不能?我可以通过Photoshop来完成,而不需要像素化图像。我错过了什么吗? – 2010-06-28 23:43:24

回答