2

我有一个应用程序可以在视网膜 iPad (iPad3) 上进行屏幕截图。或者我只是用 HOME+POWER 进行屏幕截图并以这种方式获取图像,没关系。最后,我有一个 2048x1536 的捕获图像——即 1024x768 @2x。

现在我想在屏幕上显示这个图像——这个 2048x1536 图像——我想保留它可爱的视网膜。

当我做这样的事情时(在网络浏览器中输入代码)

UIImage *myImage = [UIImage imageWithContentsOfFile: pathToMyHiresImage];
UIImageView *myImageView = [[UIImageView alloc] initWithImage: myImage];
myImageView.frame = screenBounds;  // make it fit
// etc...

我最终得到了图像的低分辨率(锯齿状对角线和文本)版本。

所以我的问题是:我必须做些什么才能将该图像重新显示在屏幕上并让它显示@2x-DPI,所以它具有漂亮的视网膜外观?

谢谢!

4

2 回答 2

1

这就是Quartz(即真实数据)和UIImage(单板)发生碰撞的地方。所以你得到了你创建的 UIImage。向它询问 CGImage,然后查看该图像。宽度和高度最好是 2048x1536 或有问题。

一旦您知道如何获得“真实”大小的图像,您可以将其保存为“foo@2x.png”,然后将其大小调整一半,并将其保存为“foo.png”。

UIImage 让没有人的事情变得非常容易,但是当你想要真正的控制时,你必须潜入 Quartz 并在橡胶碰到道路的地方工作。

我的猜测是你认为你有一个视网膜图像,但没有,然后当你去展示它的一半 rez。

于 2012-07-19T01:39:50.833 回答
1

这应该可以解决问题:

UIImage *myImage = [UIImage imageWithContentsOfFile: pathToMyHiresImage];
// *****Added Code*****
myImage = [UIImage imageWithCGImage:myImage.CGImage scale:2 orientation:myImage.imageOrientation];
// ********************
UIImageView *myImageView = [[UIImageView alloc] initWithImage: myImage];
myImageView.frame = screenBounds;  // make it fit
// etc ...

祝你好运!

编辑(Olie)这是最终代码,考虑到 DavidH 的建议:

UIImage *myImage = [[UIImage alloc] initWithContentsOfFile: path];

if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)])
{
    float screenScale = [[UIScreen mainScreen] scale];
    if (screenScale > 1.)
    {
        id oldImage = myImage;
        myImage = [[UIImage imageWithCGImage: myImage scale: screenScale orientation: myImage.imageOrientation] retain];
        [oldImage release];
    }
}
于 2012-07-19T03:55:25.927 回答