0
votes

hey guys, I have a large image, and then i'm extracting a portion of the image out via:

[mBaseImage lockFocus];
NSBitmapImageRep* bitmapImageRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect: NSMakeRect(startX,startY,width,height)];
[mBaseImage unlockFocus];

followed by:

extractedImage = [[NSImage alloc] initWithSize:[bitmapImageRep size]];
[extractedImage addRepresentation:bitmapImageRep];

where extractedImage is NSImage *.

Later on while i'm trying to draw the extractedImage using NSDrawNinePartImage, I realised that while I was specifying the 9 parts following the example at http://www.karlkraft.com/index.php/2007/11/14/nsdrawninepartimage/ I realised that when i specified 0,0 it shows the upper left handcorner of the image, which means that 0,0 is the upper left hand corner instead of the lower left hand corner like in the example in the link. I tried setting the setFlipped however it seems to be only flipping the image. does anyone have any idea how I can get the coordinates back to where 0,0 is at the bottom left?

Oh and I forgot to mention that i'm using the image as a button, so it's presented as a NSButton.

Regards, Han

1
What do you mean “it's presented as a NSButton”? It isn't possible to put an NSImage into the view hierarchy, so what exactly are you doing with the image, and what object is making the NSDrawNinePartImage call?Peter Hosey
oh sorry. this is part of a custom NSButton. The custom NSButton can have a NSImage. drawRect is overwritten to include a [image drawInRect:....]; so that the image will be drawn when the button is displayed. within the drawInRect function, there is a check if a flag useTile is set, if it is, then drawInRect will then call a function drawWithTiles and do the appropriate splitting of the image, coordinates as defined by the user before passing the 9 images to NSDrawNinePartImage.han
The example you're following will fail under a non-integral scale factor with resolution independence. :-/ Please treat code you find on the web with skepticism. It should use NSBitmapImageRep as the destination tiles instead of NSImage, as that code is specifically tied to pixels.Ken

1 Answers

0
votes

Ok i found it. It was a rogue [image setFlip:...] somewhere in the code that was causing all the mixup..