所以我有一個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,則會發生同樣的情況。
如果我保存後我加載它無需處理圖形上下文的形象我已經得到了相同的結果。 – Brian
這可以是解決方案。看看這裏:http://stackoverflow.com/questions/990550/iphone-save-image-at-higher-resolution-without-pixelating-it – UPT
你可以詳細說明 - 我不是想改變大小圖像,我只想保存的圖像與我最初打開的圖像具有相同的分辨率。 – Brian