optimizing background image drawing with -drawRect
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