Re: Doubled Pixels
Re: Doubled Pixels
- Subject: Re: Doubled Pixels
- From: Graham Cox <email@hidden>
- Date: Mon, 26 Jun 2017 11:03:49 +1000
> On 25 Jun 2017, at 7:39 pm, Gerriet M. Denkmann <email@hidden> wrote:
>
> Which of these two lines is preferable:
> NSString *colorSpaceName = useColour ? NSDeviceRGBColorSpace :
> NSDeviceWhiteColorSpace;
> NSString *colorSpaceName = useColour ? NSCalibratedRGBColorSpace :
> NSCalibratedWhiteColorSpace;
> ?
Well, it depends on what you want to do with the image. If it’s content that
gets displayed or printed, then calibrated ensures that it will look the same
across a range of devices.
>> You may want to save and restore the current context around this, just to be
>> sure your method isn’t going to have the unwanted side effect of changing
>> the current context. It’s likely OK, but better safe than sorry.
>
> I just did. Turns out that the oldContext seems to be nil. But as you rightly
> said: “better safe than sorry”.
You just needs to use +[NSGraphicsContext saveGraphicsState]; and
+[NSGraphicsContext restoreGraphicsState]; if you know currentContext is nil,
it suggests you aren’t doing it that way.
>>
>> Just use NSZeroRect for destRect. This is interpreted to mean “the size of
>> the destination image”, which is already <subRect>, rounded up. If you set
>> the size here and it’s not a whole number for some reason, there is the
>> potential for the very edge pixels not to get set, leaving a visible edge at
>> the right and bottom of the result.
>
> I tried this. But got a rather small image (just 88 bytes - usually 337
> bytes) and the resulting image looks rather empty. It has the right size, but
> not a single pixel is set - all are transparent.
OK, that’s weird. I’m not sure why that’s happening.
> But heading your warning about non-whole numbers, I added at the very start:
>
> - (NSData *)subImagePngDataWithRect: (NSRect)suxRect useColour:
> (BOOL)useColour
> {
> NSRect subRect = NSIntegralRect(suxRect);
> …
> }
Good idea.
—G.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden