所以我有一个用 [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,也会发生同样的事情。
最佳答案
iPhone 可能会以针对您的模拟器优化的分辨率加载图像。
您是否在模拟器的非视网膜显示版本上进行测试?
还有:
关于iphone - UIImage - 从 AppBundle 加载的图像以较低的分辨率保存在 App Directory 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8032528/