iphone - UIImage - 从 AppBundle 加载的图像以较低的分辨率保存在 App Directory 中

标签 iphone objective-c ios uikit uiimage

所以我有一个用 [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 可能会以针对您的模拟器优化的分辨率加载图像。

您是否在模拟器的非视网膜显示版本上进行测试?

还有:

What dpi resolution is used for an iPhone App?

关于iphone - UIImage - 从 AppBundle 加载的图像以较低的分辨率保存在 App Directory 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8032528/

相关文章:

objective-c - 将 [touches anyObject] 更改为与数组中的任何对象接触

ios - 我们可以在Windows机器上使用appium创建.ipa文件吗?

ios - 保留发送到释放的 UIViewController

ios - 如何在 iOS 6 中从 UIScrollView 中删除 UIImageView

ios - 从 UITableviewCell 中的按钮打开的下拉菜单 UIView 在单元格边界外不可单击

objective-c - 更改 UIImage 的大小

ios - 无法创建日志目录

ios - UIButton action(rx.tap) 用 RxSwift 响应不同的 PublishSubjects

ios - 如何通过 SwiftUI 中的按钮点击显示菜单?

ios - 如何在 ios 中的 UIViewController 中设置背景图像中的图像