• 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
optimizing background image drawing with -drawRect
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

optimizing background image drawing with -drawRect


  • Subject: optimizing background image drawing with -drawRect
  • From: Artemiy Pavlov <email@hidden>
  • Date: Mon, 2 Apr 2007 21:08:39 +0300

Hello all!

In the @implementation of my custom view, I have an overridden - drawRect method which puts a background image:

-(void)drawRect:(NSRect)rect{

NSString *BackgroundImageName = [[NSBundle bundleForClass:@"SpaceOscillatorViewFactory"] pathForResource:@"SpaceOscillatorUI" ofType:@"png"];
NSImage *BackgroundImage = [[NSImage alloc] initWithContentsOfFile:BackgroundImageName];


	NSSize BackgroundImageSize = NSMakeSize(763.0, 380.0);

	[BackgroundImage setSize:BackgroundImageSize];

	[BackgroundImage drawAtPoint:NSMakePoint(0.0, 0.0)
					fromRect: NSZeroRect
				    operation: NSCompositeSourceOver
					fraction: 1.0];

}


Everything is working well, but this method gets called every time any control is moved, and this causes high CPU usage spikes.


My guess is I should load and scale the image once, and use -drawRect to only do drawAtPoint. But the problem is I cannot move this part of the code outside -drawRect, I get "error: initializer element is not constant" for lines with NSString, NSImage, etc.

I would really appreciate any suggestions!


Thanks very much,

Artemiy.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: optimizing background image drawing with -drawRect
      • From: "I. Savant" <email@hidden>
    • Re: optimizing background image drawing with -drawRect
      • From: Shamyl Zakariya <email@hidden>
  • Prev by Date: Re: error displaying @count via bindings
  • Next by Date: Re: optimizing background image drawing with -drawRect
  • Previous by thread: A few bindings questions from a bindings-newbie
  • Next by thread: Re: optimizing background image drawing with -drawRect
  • Index(es):
    • Date
    • Thread