• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSImage doesn't accept background color?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >NSImage doesn't accept background color? (From: Lance Drake <email@hidden>)

  • Prev by Date: Re: Call for SplitView suggestions
  • Next by Date: Re: I can capture stderr but can't capture stdout... unless debugging?
  • Previous by thread: NSImage doesn't accept background color?
  • Next by thread: Dragging an NSImage from an NSTextView?
  • Index(es):
    • Date
    • Thread