2010-06-28 80 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

回答

相關問題