Re: Scaling a window background image quickly
Re: Scaling a window background image quickly
- Subject: Re: Scaling a window background image quickly
- From: Jean-Daniel Dupas <email@hidden>
- Date: Sun, 6 Apr 2008 12:41:39 +0200
Le 6 avr. 08 à 10:50, Heinrich Giesen a écrit :
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
The main advantage of PDF (and vector graphic in general) is that
there should not be any interpolation. By using PNG, you lose all
benefits of resolution independant graphics.
This works well with lightweight PDF, but apparently not for complex
one.
As suggested, the way to go is probably to ignore pixelisation during
resizing, and when the resizing is over, recreate a cache image from
the PDF rep. I don't know the best way to do it, but this should
probably works:
[NSImage setScalesWhenResized:YES];
[NSImage setSize:finalSizeAfterResizing];
_______________________________________________
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