我正在设置NSImages
几个CALayers
. 所有这些图像都有 4 次重复,1x、2x、5x 和 10x。当我设置 contentsScale 时,其中 3 个图像的缩放比例似乎很好,但我的视图改变时,backingScaleFactor
其中一个似乎总是选择1x表示,无论我做什么。这是我登录到控制台的图像:
<NSImage 0x1019cea60 Size={20, 24} Reps=(
"NSBitmapImageRep 0x101a0db60 Size={20, 24} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=20x24 Alpha=YES Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x101a0c8e0",
"NSBitmapImageRep 0x101a0ec90 Size={20, 24} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=40x48 Alpha=YES Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x101a0dbd0",
"NSBitmapImageRep 0x101a0fdb0 Size={20, 24} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=100x120 Alpha=YES Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x101a0ed00",
"NSBitmapImageRep 0x101a10ef0 Size={20, 24} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=200x240 Alpha=YES Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x101a0fcb0"
)>
<NSImage 0x1001faa90 Size={28, 320} Reps=(
"NSBitmapImageRep 0x101a06240 Size={28, 320} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=28x320 Alpha=YES Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x101a05230",
"NSBitmapImageRep 0x101a07370 Size={28, 320} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=56x640 Alpha=YES Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x101a062d0",
"NSBitmapImageRep 0x101a08490 Size={28, 320} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=140x1600 Alpha=YES Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x101a07400",
"NSBitmapImageRep 0x101a095c0 Size={28, 320} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=280x3200 Alpha=YES Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x101a08390"
)>
<NSImage 0x10052e790 Size={28, 40} Reps=(
"NSBitmapImageRep 0x101a01d10 Size={28, 40} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=28x40 Alpha=YES Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x101a005d0",
"NSBitmapImageRep 0x101a02de0 Size={28, 40} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=56x80 Alpha=YES Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x101a01da0",
"NSBitmapImageRep 0x101a03f00 Size={28, 40} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=140x200 Alpha=YES Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x101a02fa0",
"NSBitmapImageRep 0x101a05080 Size={28, 40} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=280x400 Alpha=YES Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x101a040c0"
)>
<NSImage 0x101bbfc40 Size={28, 600} Reps=(
"NSBitmapImageRep 0x101a0a760 Size={28, 600} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=28x600 Alpha=YES Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x101a094f0",
"NSBitmapImageRep 0x101a0b890 Size={28, 600} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=56x1200 Alpha=YES Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x101a0a7f0",
"NSBitmapImageRep 0x101a0ba60 Size={28, 600} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=140x3000 Alpha=YES Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x101a0ab10",
"NSBitmapImageRep 0x101a0c9b0 Size={28, 600} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=280x6000 Alpha=YES Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x101a0b920"
)>
第三个 (28 x 40) 始终以 1x 绘制。这是我用来设置比例因子的代码:
- (void)viewDidChangeBackingProperties {
[super viewDidChangeBackingProperties];
self.layer.contentsScale = self.window.backingScaleFactor;
self.otherLayer.contentsScale = self.window.backingScaleFactor;
self.otherLayer.contents = self.image;
}
我再次将图层内容设置为图像,因为在这个问题中确定了CALayer
选择绘制时间的最佳表示,NSImage
并且需要再次设置。
我在所有图像上运行了新-recommendedLayerContentsScale:
方法,当给定 2.0 时,它们都返回 2.0,除了没有正确缩放的图像。
编辑:我将损坏的图像写入一个文件,然后在另一个应用程序中打开一个新NSImage
的 -initWithContentsOfFile
在另一个应用程序中,我把它放在一个文件中NSImageView
,问题仍然存在!它适用于其中一个正在工作的图像。显然,Apple 的图像选择代码有问题。