> On Mar 6, 2014, at 9:25 AM, Leonardo <mac.iphone....@gmail.com> 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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to