Re: Draw image within a NSBezierPath with no border
Re: Draw image within a NSBezierPath with no border
- Subject: Re: Draw image within a NSBezierPath with no border
- From: Leonardo <email@hidden>
- Date: Tue, 11 Mar 2014 20:28:20 +0100
- Thread-topic: Draw image within a NSBezierPath with no border
Hi Kyle,
thank you for your suggestions, but the clearColor doesn't cast shadow. I
tried the transparency layers too, but when I export the view to a PDF using
dataWithPDFInsideRect, I get no compression (specified in the quartzFilter).
Instead, If I do not use the transparency layers, I properly get the
compression.
pdfData = [printView dataWithPDFInsideRect:printRect];
pdfDoc = [[PDFDocument alloc] initWithData:pdfData];
[pdfDoc writeToFile:outFilePath withOptions:optionsDictWithQuartzFilter];
By ³get the shadow out of the fillPath² I mean that I have a view 100 x 100
pixels, I draw an image 50 x 50 in the center of the view, so the shadow
should be well visible. But since I clip the image rect, the shadow doesn't
appear.
Regards
-- Leonardo
> Da: Kyle Sluder <email@hidden>
> Data: Thu, 6 Mar 2014 09:54:04 -0800
> A: Leonardo <email@hidden>
> Cc: Kevin Meaney <email@hidden>, "email@hidden"
> <email@hidden>
> Oggetto: Re: Draw image within a NSBezierPath with no border
>
>
>> On Mar 6, 2014, at 9:25 AM, Leonardo <email@hidden> wrote:
>>
>> That's make sense. Do you know any workaround?
>> I have to draw the background color because:
>> 1) the user could choose to see a background color on the area not
>> covered by the image. Let's imagine a circle divided in 3 slices by two
>> vertical lines. In the middle we have the image, and on the left and right
>> areas we see the color. So, at the top and bottom of the image I see that
>> bad blue curved border.
>
> Create a CGLayer from your destination context that is the size of your image.
> Fill it with your background color. Draw your image into it. Set the clipping
> path on the destination context. Draw the CGLayer into the destination
> context.
>
>> 2) In case of shadow, if I do not fill with a color before clipping the
>> path I can't get the shadow out of the path. If I do
>>
>> CGContextSetShadowWithColor...
>> [fillPath addClip];
>> [image drawInRect:fillBounds fromRect:NSZeroRect
>> operation:NSCompositeSourceOver fraction:1.0];
>>
>> I can't get the shadow out of the fillPath.
>
> I don¹t know what you mean by ³get the shadow out of the fillPath².
>
> Do you mean that you don¹t want the shadow to appear below transparent parts
> the your image?
>
>> Instead If I do:
>>
>> CGContextSetShadowWithColor...
>> [aBlueColor set];
>> [fillPath fill];
>> RemoveShadow
>> [fillPath addClip];
>> [image drawInRect:fillBounds fromRect:NSZeroRect
>> operation:NSCompositeSourceOver fraction:1.0];
>>
>> The problem is that I must clip the path before drawing the image, and as
>> result the image itself can't project shadow outside the clipped path.
>> I am puzzled.
>
> If you use my above technique, you should be able to create the shadow and
> then draw the layer on top of it:
>
> - drawRect: {
> // Draw the shadow
> CGContextSaveGState();
> NSBezierPath *oval = ;
> [[NSColor clearColor] setFill];
> CGContextSetShadowWithColor();
> [oval fill];
> CGContextRestoreGState();
>
> // Draw the clipped image
> CGLayerRef layer = MakeLayerFromImage();
> CGContextSaveGState();
> [oval addClip];
> CGLayerDrawAtPoint(layer, );
> CGContextRestoreGState();
> }
>
> This might not work. I¹m unsure of the behavior of Quartz shadows when drawing
> with +clearColor. If it doesn¹t work, you might want to look into Quartz
> transparency layers (which are not the same thing as CGLayerRefs).
>
> --Kyle Sluder
_______________________________________________
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