Re: NSImage doesn't accept background color?
Re: NSImage doesn't accept background color?
- Subject: Re: NSImage doesn't accept background color?
- From: Ricky Sharp <email@hidden>
- Date: Sat, 25 Sep 2004 21:34:55 -0500
On Sep 25, 2004, at 9:21 AM, Lance Drake wrote:
An NSimageView* myImageView exists but it's empty of an image.
Test: add an image to the image view - it WILL/DOES display.
If I have no image - I would like to, instead, show a color.
I create an NSImage* image = [[NSImage alloc] initWithsize: size];
The 'size' of the NSImage can be confirmed as being set correctly.
There is an NSColor* myColor that has been initialized;
I call [image setBackgroundColor:myColor];
[myImageView setImage:image];
The result: Nothing is displayed.
Can anyone suggest what is wrong or if there is some other way to
handle this?
As mentioned in the docs on that API, the bg color isn't visible for
certain representations of the image.
The following should do what you want:
NSImage* image = [[NSImage alloc] initWithSize:size];
NSRect imageBounds = NSMakeRect (0, 0, size.width, size.height);
[image lockFocus];
[myColor set];
NSRectFill (imageBounds);
[image unlockFocus];
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden