2010-03-08 172 views
1

我正在開發一個iPhone應用程序,調整和合並圖像。iPhone:如何保持原始圖像大小盡管圖像編輯

我想從照片庫中選擇兩張尺寸爲1600x1200的照片,然後將兩張照片合併成一張圖像並將該新圖像保存回照片庫。

但是,我無法獲得合併圖像的正確尺寸。

我把幀320x480的兩個圖像視圖,並將視圖的圖像設置爲我導入的圖像。操作圖像(縮放,裁剪,旋轉)後,我將圖像保存到相冊中。當我檢查圖像大小時,顯示600x800。我如何獲得1600 * 1200的原始尺寸?

我一直在這個問題上停留兩週!

在此先感謝。

+0

問題可能是太含糊回答 - 嘗試是模式詳細和具體的 – 2010-03-08 12:54:07

+0

感謝答覆, 我使用尺寸1200 * 1600的兩個圖像。爲了iPhone的兼容性,我正在採取320 * 480的圖像視圖來顯示兩個圖像...之後,即時通訊從這兩幅圖像中繪製出一個新的圖像,其尺寸爲320 * 480,但我需要它的原始尺寸爲1200 * 1600尺寸..我怎樣才能得到。目前正在調整圖像的大小爲1200 * 1600,但它給我模糊的圖像。 – Madhu 2010-03-08 13:02:16

回答

0

解決如下。

UIView *bgView = [[UIView alloc] initwithFrame:CGRectMake(0, 0, 1600, 1200)]; 
UIGraphicsBeginImageContext(tempView.bounds.size); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
UIImageWriteToSavedPhotosAlbum(viewImage, self, nil, nil); 

感謝您的支持,以解決這一問題

0

UIImageView的框架與它顯示的圖像大小無關。如果您在75x75 imageView中顯示1200x1600像素,則內存中的圖像大小仍爲1200x1600。在處理圖像的某個地方,您將重置其大小。

您需要在後臺以編程方式調整圖像大小,並忽略它們的顯示方式。爲了獲得最高保真度,我建議在全尺寸上預先處理圖像上的所有處理,然後調整最終結果的大小。對於速度和內存使用量低的情況,首先調整較小的尺寸,然後根據需要重新調整尺寸。

我使用Trevor Harmon's UIImage+Resize來調整圖像大小。

他的核心方法是這樣的:

- (UIImage *)resizedImage:(CGSize)newSize 
       transform:(CGAffineTransform)transform 
      drawTransposed:(BOOL)transpose 
    interpolationQuality:(CGInterpolationQuality)quality 
{ 
    CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height)); 
    CGRect transposedRect = CGRectMake(0, 0, newRect.size.height, newRect.size.width); 
    CGImageRef imageRef = self.CGImage; 

    // Build a context that's the same dimensions as the new size 
    CGContextRef bitmap = CGBitmapContextCreate(NULL, 
               newRect.size.width, 
               newRect.size.height, 
               CGImageGetBitsPerComponent(imageRef), 
               0, 
               CGImageGetColorSpace(imageRef), 
               CGImageGetBitmapInfo(imageRef)); 

    // Rotate and/or flip the image if required by its orientation 
    CGContextConcatCTM(bitmap, transform); 

    // Set the quality level to use when rescaling 
    CGContextSetInterpolationQuality(bitmap, quality); 

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

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

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

    return newImage; 
} 

哈蒙救了我幾十個工時試圖讓尺寸調整正確。

+0

感謝回覆, 我也是這樣做..處理所有的代碼在調整大小的圖像,然後再次調整大小。但它會造成圖像模糊...但圖像不必失去其原始質量。 – Madhu 2010-03-08 15:16:01

+0

如果調整邏輯(與顯示器相反)圖像的大小,您將不可避免地鬆開某些分辨率,因爲調整大小算法必須按順序執行一些內插/外插縮小/擴大圖像。這樣做會破壞最初定義圖像的一些信息。 – TechZen 2010-03-08 17:36:44

+0

當決定以最高保真度執行圖形處理的順序時,應該按照最少改動的順序進行。例如複合 - >裁切 - >旋轉 - >縮放 - >調整大小。 – TechZen 2010-03-08 17:40:07

相關問題