How to get perfect pixel pattern with cocoa

I'm trying to draw some elements of my interface in Cocoa, mostly icons for buttons, but it is very difficult for me to get the accuracy I would like.

I use super simple code like this to draw rectangles:

[[NSColor redColor] set];
[NSBezierPath strokeRect:myRect];

But I see that the red line of the rectangle has always faded.

What am I missing here?

+3
source share
2 answers

The Cocoa coordinates actually determine the center of the pixel you want to draw. This means, for example, that if you want to draw the bottom left pixel, you must use the coordinates (0.5.0.5).

Add / subtract half a pixel to your coordinates, and they should be perfect for a pixel.

+8
source

:

[[NSGraphicsContext currentContext] setShouldAntialias:NO];

NSFrameRect , , :

NSFrameRect(myRect);
0

Source: https://habr.com/ru/post/1791190/


All Articles