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: glenn andreas <email@hidden>
- Date: Thu, 27 Feb 2014 10:20:58 -0600
A PDF file can "reuse" an image and draw the same thing multiple times in multiple places. If it saved just the clipped version, it would need multiple copies of the same image, which would actually increase the file size.
So if the purpose of adding a "cropImages" flags was to save file space, in some case it will result in taking more space.
Furthermore, if the image is a jpg image, clipping would need the image to be recompressed and end up degrading the image quality (since PDFs can embed jpg files directly), or again, potentially increase the file size.
And if you draw a PDF image inside the view, those PDF instructions/objects are encoded into the resulting file - if you want to clip that, you either need to rasterize it (loosing quality) or perform clipping operations on shapes to produce new ones (which can be non-trivial).
On Feb 27, 2014, at 9:57 AM, Leonardo <email@hidden> wrote:
> 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
_______________________________________________
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