【发布时间】:2011-12-23 08:51:41
【问题描述】:
所以我有一个使用[UIImage imageNamed] 加载的 UIImage。然后我将该文件保存到我的文档目录中。我的问题是该文件最初具有 240 分辨率。当我从模拟器的文档目录中检索文件时,它现在具有 72 分辨率。如何以与加载时相同的分辨率保存它?
这是我的加载方式:
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,也会发生同样的事情。
【问题讨论】:
-
如果我在加载图像后立即保存图像而不处理图形上下文,我会得到相同的结果。
-
这可能是解决方案。看看这里:stackoverflow.com/questions/990550/…
-
您能否详细说明一下 - 我不是要更改图像的大小,我只是希望保存的图像与我最初打开的图像具有相同的分辨率。
标签: iphone objective-c ios uikit uiimage