Re: Scaling a window background image quickly
Re: Scaling a window background image quickly
- Subject: Re: Scaling a window background image quickly
- From: Heinrich Giesen <email@hidden>
- Date: Sun, 6 Apr 2008 10:50:30 +0200
Hi,
your PDF image is a beast, its size is 624 kB and contains a lot of
complicated structures.
I converted the PDF into an equivalent (same size and with alpha) PNG-
file with only 28 kB.
But that is only important for the first drawing where an NSImage
with only one representation
(NSPDFImageRep) is created and rendered. For the following drawings
there is not a big difference.
In your code you use:
[gStickyImage setCacheMode:NSImageCacheNever] ;
This is deadly and makes it slow, because rendering starts from
scratch, the PDF-file, not from the NSImage object.
For a sharp (not pixelated) image you need to setDataRetained:YES.
This is explained in the docs
(NSImage -> -setDataRetained: ) and was discussed alot in this list.
Using Jean-Daniel's code snippet as a starting point I tried this
with success (sharp and fast):
- (void)drawRect:(NSRect)aRect {
if (!gSticky) {
gSticky = [NSImage imageNamed:@"sticky"];
[gSticky setDataRetained:YES];
}
[gSticky drawInRect:[self bounds] fromRect:NSZeroRect
operation:NSCompositeSourceOver fraction:1];
}
You may also set the imageInterpolation to NSImageInterpolationHigh,
but only if
you are not in the state of "inLiveResize"
Heinrich
--
Heinrich Giesen
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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