CALayer NSImage content does not pick the correct view

I am setting NSImages

in the content of several CALayers

. All of these images have 4 repetitions, 1x, 2x, 5x and 10x . 3 of these images seem fine when I set contentsScale when my view changes it backingScaleFactor

, but one of them seems to always select the 1x view no matter what I do. Here are my images entered the console:

<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"
)>

      

The third (28 x 40) is always drawn at 1x. Here is the code I am using to set the scale factor:

- (void)viewDidChangeBackingProperties {
    [super viewDidChangeBackingProperties];
    self.layer.contentsScale       = self.window.backingScaleFactor;
    self.otherLayer.contentsScale  = self.window.backingScaleFactor;

    self.otherLayer.contents = self.image;
}

      

I set the content of the layer again because it was stated in this question that it CALayer

picks the best view NSImage

when drawing it and will need to be set again.

I ran a new method -recommendedLayerContentsScale:

on all of my images and they all returned 2.0 when given 2.0, except for the one that doesn't scale correctly.

EDIT: I wrote the split image to a file and then opened a new one NSImage

with - initWithContentsOfFile

in another application and I put it in NSImageView

and the problem persists! He works with one of the images that worked. Obviously there is something wrong with Apple's code selection.

+3


source to share





All Articles