2011-11-07 16 views
1

所以我有一個UIImage,我加載了[UIImage imageNamed]。然後將該文件保存到我的文檔目錄中。我的問題是,該文件最初有240分辨率。當我從模擬器的文檔目錄中檢索文件時,它現在有72個分辨率。我怎樣才能將它保存爲與載入的分辨率相同的分辨率?UIImage - 從AppBundle加載的圖像以較低的分辨率保存在應用程序目錄中

這是我如何加載:

UIImage * image = [UIImage imageNamed:@"halloween_big.jpg"] 
CGContextRef context = CGBitmapContextCreate(
                (void*) pixels, 
                image.size.width, 
                image.size.height, 
                8, 
                image.size.width * 4, 
                CGImageGetColorSpace(image.CGImage), 
                kCGImageAlphaPremultipliedLast 
                ); 

// get the image from the current context with our new pixels 
CGImageRef imageRef = CGBitmapContextCreateImage(context); 

image = [UIImage imageWithCGImage:imageRef]; 

編輯 - 我也通過圖像與眼前這個加載和作出任何更改圖像嘗試:

UIImage *loaded = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"halloween_big" ofType:@"jpg"]]; 

下面是我保存它:

NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"]; 
[UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES]; 

編輯 - 如果我將文件另存爲PNG,我會得到相同的分辨率損失。

可以肯定的是,如果我將質量參數更改爲UIImageJPEGRepresentation,則會發生同樣的情況。

+0

如果我保存後我加載它無需處理圖形上下文的形象我已經得到了相同的結果。 – Brian

+0

這可以是解決方案。看看這裏:http://stackoverflow.com/questions/990550/iphone-save-image-at-higher-resolution-without-pixelating-it – UPT

+0

你可以詳細說明 - 我不是想改變大小圖像,我只想保存的圖像與我最初打開的圖像具有相同的分辨率。 – Brian

回答

0

iPhone很可能會爲您的模擬器加載具有優化分辨率的圖像。

您是否在模擬器的非視網膜顯示器版本上進行測試?

另外:

What dpi resolution is used for an iPhone App?

+0

我試過在iPhone模擬器中使用和不使用Retina。我還將它追溯到我對圖像做任何事情之前。只要它作爲UIImage加載 - 我將它寫入磁盤並且其分辨率爲72.我嘗試使用imageNamed和initWithContentsOfFile加載UIImage。 – Brian

+0

你在實際設備上看到不同的結果嗎? –

+0

我還沒有在設備上試過它。我想這是一種可能性。我仍在早期開發試圖製作原型。 – Brian

相關問題