Re: Extracting a (smooth) rect from an NSImageView displaying PDF?
Re: Extracting a (smooth) rect from an NSImageView displaying PDF?
- Subject: Re: Extracting a (smooth) rect from an NSImageView displaying PDF?
- From: Brock Brandenberg <email@hidden>
- Date: Tue, 13 May 2003 21:02:48 -0500
>
> In my app I have an NSImageView displaying a PDF file. I'd like the user to
>
> be able to extract a rectangular region from the displayed PDF and view it
>
> at 10x normal size.
>
>
>
> The problem is that, although this *does* extract the rectangular region
>
> between mouseDown (the upper-left corner) and mouseUp (the lower-right
>
> corner) and displays it in the zoomImageView, it's extremely jagged...
>
> Almost as if the PDF data is merely a PDF wrapper containing the screen
>
> bitmap. What do I need to do in order to get the "real" PDF data so that I
>
> can scale the region smoothly?
>
>
Actually, the image displayed in the imageview IS a bitmap (chached
>
version of the PDF). I am afraid you have to draw the whole PDF at 10x
>
the size of MyImageView into an image and then clip the rect from
>
there. This way, you force the (new) NSImage to fetch the PDF data
>
again and render it at the enlarged size.
Jason,
To keep from getting a bitmap from a PDF, you simply need to understand the
way that NSImage handles and renders PDF data. Normally, when you allow an
NSImage instance to open and render PDF data for you, it will generate a
NSCachedImageRep from it and discard the original data. You can see this
behavior if you log the representations at different times, both right after
the NSImage is created and after it is told to draw for the first time.
What you really want to do is work around this default NSImage behavior by
creating an NSImageRep from the PDF data (you'll get a NSPDFImageRep), then
add the rep to an empty NSImage and tell the NSImage to retain the data. By
doing so, the NSImage will depend on the PDF rep instead of a
NSCachedImageRep when it's asked to draw.
NSImage *srcPDF;
NSImageRep *srcPDFRep;
srcPDFRep = [NSPDFImageRep imageRepWithContentsOfFile:@"myFile"];
srcPDF = [[NSImage alloc] init];
[srcPDF setDataRetained:YES];
[srcPDF addRepresentation:srcPDFRep];
[srcPDF setSize:[srcPDFRep bounds].size];
This should get you pointed in a constructive direction :)
Brock Brandenberg
----- industrial design @ www.bergdesign.com ------
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.