• 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: drawing an image in an NSRect?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: drawing an image in an NSRect?


  • Subject: Re: drawing an image in an NSRect?
  • From: p3consulting <email@hidden>
  • Date: Tue, 2 Mar 2004 12:37:02 +0100

On 2 mars 2004, at 02:31, Iain Wood wrote:

On 1 Mar 2004, at 21:24, p3consulting wrote:
@implementation DarkSliderCell
-(void)drawKnob:(NSRect)knobRect
{
//[[NSColor blueColor] set];
//[NSBezierPath fillRect:knobRect];
knobImage=[[NSImage alloc] initWithContentsOfFile:@"/Users/ndiw/prog/Nova/darkKnob.jpg"];
[knobImage setSize:knobRect.size];
[knobImage compositeToPoint:NSZeroPoint operation:NSCompositeSourceOver];


Have you tried
[knobImage compositeToPoint: knobRect.origin operation:NSCompositeSourceOver];


Thanks, that gave me the clue I was needing. I had to modify it slighly to get the image in the right place ie:

[knobImage compositeToPoint: NSMakePoint(knobRect.origin.x,knobRect.origin.y+knobRect.size.height) operation:NSCompositeSourceOver];



(you should cache the image...)



I was going to try creating the NSImage in an init method. Is that what you mean?



init is a good place to do it indeed,
and what I mean is:
avoid memory allocation and disk access in a drawing routine that is called so often
that doesn't help performance.

also the path should not be absolute but relative to your application bundle
(put the image in the Resources of your app, see NSBundle doc)

Pascal Pochet
email@hidden
_______________________________________________
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.


References: 
 >drawing an image in an NSRect? (From: Iain Wood <email@hidden>)
 >Re: drawing an image in an NSRect? (From: p3consulting <email@hidden>)
 >Re: drawing an image in an NSRect? (From: Iain Wood <email@hidden>)

  • Prev by Date: CFPreferences & NSArray*
  • Next by Date: Re: CFPreferences & NSArray*
  • Previous by thread: Re: drawing an image in an NSRect?
  • Next by thread: Can't complete drop operation...
  • Index(es):
    • Date
    • Thread