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: Marco Binder <email@hidden>
- Date: Wed, 14 May 2003 12:38:51 +0200
Sorry, I guess I wrote *bs*. Forget the first paragraph of my previous
mail. You HAVE to do it manually as Brock suggested.
Marco
Am Mittwoch, 14.05.03 um 10:55 Uhr schrieb Marco Binder:
This is of course right if you talk about a NSImage that you set up
yourself. If, however, the user can drag a PDF into your imageview,
you either have to subclass NSImageView to make a retaining image or
you have to render the pdf into a secondary NSImage of the desired
size, whenever you want to display the enlarged view.
Brocks solution is of course the more sound one that gives you a high
degree of control over the image. Actually, I myself do prefer working
with imagereps much rather than working with NSImage for exactly that
reason. With NSImage, you have to figure out and understand the way it
caches image data, otherwise you will run into trouble like this
sooner or later.
Marco
Am Mittwoch, 14.05.03 um 04:02 Uhr schrieb Brock Brandenberg:
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 ------
--
|\ /| email@hidden http://www.marco-binder.de
| \/ | Telefon: 07531 / 94 19 94 Fax: 07531 / 94 19 92
| |ARCO Snail-Mail: Banater Str. 3 - 78467 Konstanz
BINDER _____________________________________________________
_______________________________________________
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.
--
|\ /| email@hidden
http://www.marco-binder.de
| \/ | Telefon: 07531 / 94 19 94 Fax: 07531 / 94 19 92
| |ARCO Snail-Mail: Banater Str. 3 - 78467 Konstanz
BINDER _____________________________________________________
_______________________________________________
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.