tags:

views:

27

answers:

2

Hello, I have a function receiving a Drawing that I need to partially expose as a DrawingImage (i.e.: its position and size will be reduced/changed to fit in a target area).

How can I crop/clip a region of the original Drawing? Or maybe it is easier to do that after the transformation to DrawingImage (how clip that DrawingImage)?

A: 

I am a little confused on what you are asking but maybe my answer to this similar question will help?

http://stackoverflow.com/questions/2610114/how-can-i-use-a-pathgeometry-as-a-mask-for-a-bitmapsource-or-any-image-data/2615049#2615049

Foovanadil
Sorry, i mean DrawingImage instead of Image.
Néstor Sánchez A.
Right, but I still don't understand how you need to use it. A DrawingImage can be set as the Source of an Image control. In this case, my linked solution of setting the image.clip property I think will get what you want?
Foovanadil
I need to do that in a library function, where is not known yet where/how the result will be used (e.g. that Image control you propose).
Néstor Sánchez A.
A: 

The solution was to encapsulate the original Drawing in a DrawingGroup and then apply a clipping geometry...

public void MyClippingFunc(Drawing OriginalDrawing, Rect ClippingArea)
{
    var Group = new DrawingGroup();
    Group.Children.Add(OriginalDrawing);
    Group.ClipGeometry = new RectangleGeometry(ClippingArea);

    return Group;
 }
Néstor Sánchez A.