Re: dataWithPDFInsideRect doesn't clip images within NSView
Re: dataWithPDFInsideRect doesn't clip images within NSView
- Subject: Re: dataWithPDFInsideRect doesn't clip images within NSView
- From: Leonardo <email@hidden>
- Date: Thu, 27 Feb 2014 16:57:08 +0100
- Thread-topic: dataWithPDFInsideRect doesn't clip images within NSView
Thank you. I have coded it. I lock the focus of the NSView, I draw and get
the clipped image, then I re-draw the NSView with the clipped image +
borders, rotation, shadow. Of course, since the user could choose the ppi
output, I resize-resample the view before locking it.
It should be useful to have an option as
[view dataWithPDFInsideRect:bounds clipPaths:YES];
Regards
-- Leonardo
> Da: Graham Cox <email@hidden>
> Data: Thu, 27 Feb 2014 22:38:42 +1100
> A: Leonardo <email@hidden>
> Cc: Cocoa-dev List List <email@hidden>
> Oggetto: Re: dataWithPDFInsideRect doesn't clip images within NSView
>
>
> On 27 Feb 2014, at 9:31 pm, Leonardo <email@hidden> wrote:
>
>> I draw an NSImage within an NSView scaling its size in order to fill the
>> image within the view bounds. The image is larger than the NSView's bounds,
>> but on the display it looks well clipped to those bounds.
>>
>> Since the image's NSView is a subView of the page's NSView, I create a PDF
>> saving that page's NSView
>>
>> [pageView dataWithPDFInsideRect:pageRect];
>>
>> and I get a pdf file. Anyway, when I inspect the pdf file with Acrobat, I
>> clearly see that the image hasn't been cropped. As I see from the blue
>> rectangle around the visible small image, the whole original and larger
>> image has been embedded within the pdf document.
>> In facts if I Control-Click-Edit the image on the pdf, I get the original
>> whole image. So the pdf file size results bigger than what it would really
>> be. I don't get this trouble when saving the page to a TIFF or any other
>> raster image file (with NSBitmapImageRep -> CGImage ->
>> displayRectIgnoringOpacity -> CGImageDestinationFinalize).
>
>
> This is exactly what you'd expect. Core Graphics basically *is* a PDF. So when
> you draw an image into a view that is clipped, all you're doing is setting a
> clipping path and drawing an image. The PDF faithfully records that.
>
> When you create a different image that is clipped to the smaller area, then
> that's what is recorded.
>
>> My question:
>> Do you know an option, any API, to clip the image to its NSView's frame on
>> the pdf, as it properly looks on the display? Or should I clip the image by
>> my own code?
>
>
> When you know how it works, the question becomes moot. The short answer is
> 'no', there's no API. You have to resample/crop the image as you need, or
> accept the larger filesize for the convenience that you get from the simple
> API.
>
> --Graham
>
>
_______________________________________________
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