Re: Placing an NSRect into an NSImage
Re: Placing an NSRect into an NSImage
- Subject: Re: Placing an NSRect into an NSImage
- From: "John C. Randolph" <email@hidden>
- Date: Wed, 11 Dec 2002 17:16:43 -0800
On Wednesday, December 11, 2002, at 03:25 PM, Simone Manganelli wrote:
OK, so I've quit messing around with NSProgressIndicators, since it's
too complicated, and I've decided to make my own little progress bars
to display in an NSTableView.
Problem is, I know how to create and draw in the NSRect, but I want to
output the NSRect to an NSImage that can be stored, so when the
NSTableView asks for the image, it's there. I can only seem to find
out how to draw an image into a view/rect, not a rect into an image.
Can someone help me with this?
float width, height; // set them to whatever size you need them to
be...
NSRect myRect;
...
NSImage *myImage = [[NSImage alloc] initWithSize:NSMakeSize(width,
height)];
[myImage lockFocus];
[[NSColor blackColor] set]; // Actually, black is the default but I
like to be explicit.
NSFrameRect(myRect);
[myImage unlockFocus];
myRect has now been drawn on myImage.
One thing to keep in mind: the coordinate space of an NSImage is
flipped by default. If you want to change it, you'll need to use the
NSAffineTransform class directly instead of the coordinate space
manipulation methods available in an NSView. (An NSImage isn't a view.)
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.