Re: NSImage and zooming PDFs vs. bitmaps
Re: NSImage and zooming PDFs vs. bitmaps
- Subject: Re: NSImage and zooming PDFs vs. bitmaps
- From: "Ken Ferry" <email@hidden>
- Date: Fri, 8 Aug 2008 09:53:29 -0700
Hi Hamish,
The correct answer is to call setDataRetained:YES on your image.
However, there may be a bug in Leopard and previous with NSImage cache
expiration that prevents that from being enough. If you seem to be
hitting it, you can probably work around it by additionally turning
off caching entirely (setCacheMode:NSImageCacheNever) or maybe by
manually invalidating the image cache (-[NSImage recache]) when you
are changing the scale.
This is a common source of unexpected behavior with NSImage. The deal
is that unless you advise it otherwise with setDataRetained:, NSImage
is permitted to throw out original backing data and specialize itself
to wherever its being used. NSImage can throw out the PDF rep (as you
saw) and save a representation that is only good for the one context
you used it in. This is actually kind of a nice behavior if you
expect it and turn it off when its inappropriate, but right now it's
difficult to understand. Plus, like I said, bugs in cache expiration
make the whole behavior less predictable.
-Ken
On Fri, Aug 8, 2008 at 9:25 AM, Hamish Sanderson
<email@hidden> wrote:
> Hi all,
>
> I'm writing a Core Animation-based image viewer application for use with
> both bitmap (TIFF, JPEG) and vector (EPS, PDF) images but I'm rather new to
> this stuff and am struggling to get the zooming feature to work well with
> vector images.
>
> Image files are loaded via -[NSImage imageWithContentsOfFile:]. Zooming is
> achieved by halving/doubling the size of the source rect when calling
> -[NSImage drawInRect:fromRect:operation:fraction:] to draw a smaller/larger
> portion of the image into the destination rect.
>
> Bitmap images work exactly as expected. Vector images, however, also become
> blocky when zoomed in which isn't what you'd hope for with a
> resolution-independent format.
>
> As far as I can tell, an NSImage instance created from a PDF file initially
> contains an NSPDFImageRep containing the original resolution-independent
> image data. The first time -drawInRect... is called, the PDF data is
> rasterised and the NSImage's NSPDFImageRep is replaced by an
> NSCachedImageRep. That makes sense from a performance point of view, I
> guess, but it rather assumes that I won't want to draw that image at
> different sizes later on.
>
> The resulting NSImage looks fine on screen as long as it's displayed at the
> size it's first drawn; the problem is, how do I persuade NSImage to
> re-rasterise the PDF data at a higher resolution when I zoom in or lower
> resolution when I zoom out so that it always produces a high-quality
> display?
>
> Many thanks,
>
> Hamish
> --
>
> Hamish Sanderson
> Production Workflow Developer
> Sun Branding Solutions Ltd
> Tel: +44(0)1274 200 700
> www.s-brandingsolutions.com
>
>
>
>
> _______________________________________________
>
> 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
>
_______________________________________________
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