Image 如何显示图像以及OSX预览?

Image 如何显示图像以及OSX预览?,image,macos,nsview,preview,nsimage,Image,Macos,Nsview,Preview,Nsimage,我试图在自定义视图中显示myPhoto.JPG。我通过以下方式调整myBox进行缩放: [myImage drawInRect:myBox fromRect:NSZeroRect操作:NSCompositeSourceOver分数:1.0] 不幸的是,当我放大到足以看到单个像素时,像素边缘模糊。相反,当我在预览中打开同一张照片时,像素边缘干净而清晰。(此外,缩放和平移在预览中更加流畅。) 如果您能想到如何在自定义视图中实现预览级质量,我将不胜感激。在drawRect:中替换该行 [myImage

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

[myImage drawInRect:myBox fromRect:NSZeroRect操作:NSCompositeSourceOver分数:1.0]

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


如果您能想到如何在自定义视图中实现预览级质量,我将不胜感激。

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

(参见
NSGraphicsContext
中的
setImageInterpolation:
文档)

完美!非常有用。感谢您提供指向相应文档的指针。我现在正在仔细阅读。