如何显示图像以及OS X预览?

时间:2012-10-30 06:19:58

标签: image macos nsview preview nsimage

我正在尝试在自定义视图中显示myPhoto.JPG。我正在通过调整myBox进行缩放:

[myImage drawInRect:myBox fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];

不幸的是,当我放大到足以看到单个像素时,像素边缘模糊。相比之下,当我在预览中打开相同的照片时,像素边缘干净而清晰。 (此外,缩放和平移在预览中更加流畅。)

我非常感谢有关如何在自定义视图中实现预览级别质量的任何想法。

1 个答案:

答案 0 :(得分:1)

drawRect:替换

[myImage drawInRect:myBox fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];

这些行:

NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
NSImageInterpolation currentValue = [currentContext imageInterpolation];
[currentContext setImageInterpolation:NSImageInterpolationNone];
    [myImage drawInRect:myBox fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
[currentContext setImageInterpolation:currentValue];   // restore the old value

(请参阅setImageInterpolation:中的NSGraphicsContext的文档)