Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSDrawNinePartImage gaps

I am working on drawing custom buttons/textfields with NSDrawNinePartImage. I slice up an image into nine parts in code and draw it into a rect with NSDrawNinePartImage.

Unfortunately I am getting some gaps in the drawing pattern. I thought it had something to do with my slicing code, but I saved them out as images from where I slice them, and they all look good (I even put them together and they looked good). Some of the cases where I use it to work just fine though despite some using the same images.

I am pretty confident that it comes down to the actual drawing.

Do you know of any NSGraphicsContext or other settings that would affect it or something else that may be causing this?

With gaps

With gaps

Without gaps

Without gaps

like image 506
Justin Meiners Avatar asked Jun 04 '11 17:06

Justin Meiners


2 Answers

I fixed a similar issue by disable the anti-alias option

NSGraphicsContext* theContext = [NSGraphicsContext currentContext];
[theContext saveGraphicsState];
[theContext setShouldAntialias: NO];
NSDrawNinePartImage(...);
[theContext restoreGraphicsState];
like image 93
Gong Pengjun Avatar answered Oct 09 '22 22:10

Gong Pengjun


Is it possible that your upper left and lower right images are a pixel too wide?

This function uses the top-left and bottom-right corner images to determine the widths and heights of the edge areas that need to be filled. If the width or height of the bottom-left and top-right images are not sized appropriately, they may be scaled to fill their corner area. Edge areas between the corners are tiled using the corresponding image. Similarly, the center area is tiled using the specified center image.

like image 33
Grady Player Avatar answered Oct 09 '22 23:10

Grady Player