crop an ellipse from a wrtabmp

Oct 14, 2010 at 2:06 PM

Hey Hi....

I use a lot of the WriteableBitmapEx (thxAlot!!!), and now i wanted to crop a region (ellipse) from a wrtabmp. I have the wrtabmp and all the ellipse parameters i need to crop from it, like xc,yc,yr,xr.

please any help or suggetsions...

cya & thx


Oct 14, 2010 at 2:13 PM

Only rectangular regions can be cropped with the Crop method. However, you can use the Blit method for masking.

  1. Create a new white (or any color) WBmp. See the Clear(Color) method.
  2. Draw a transparent ellipse to it. (Color set to 0x00000000 -> Meaning alpha is zero).
  3. Blit the new WBmp over the image you want to crop by using Alpha as BlendMode.

- Rene Schulte

Oct 14, 2010 at 3:48 PM

OK^^Thx for the help!!!



Oct 27, 2010 at 8:12 AM

OK, I had some other difficulties, but know I needed this^^but cant apply It correct :(

So what i have:

1. I have the coordinates of the ellipse, it is a region of the original an image, like this :

 wbOverlayeyEllipseFace.DrawEllipseCentered((c.X) - 1, (c.Y) - 1, s.Width >> 1, s.Height >> 1, Colors.Transparent);

2. I cant crop the ellipse out, so I crop a rectangle from the image, but I want the regions, whene i take the ellipse virtually above it, out of the ellipse being transparent on the croped area:

 wbOverlayedRectFace = selectedSnapshot.Crop((c.X - (s.Width / 2)), (c.Y - (s.Height / 2)), s.Width, s.Height);

Now I tried the blitting but I think I miss something....? What i made/tried is this:

 wbOverlayeyEllipseFace = new WriteableBitmap(s.Width, s.Height);


 wbOverlayeyEllipseFace.DrawEllipseCentered((c.X) - 1, (c.Y) - 1, s.Width >> 1, s.Height >> 1, Colors.Transparent);

??? wbOverlayedRectFace.Blit(???, wbOverlayeyEllipseFace, ???, WriteableBitmapExtensions.BlendMode.Alpha);

Hm, maybe it is to early for me.....pls can someone help me out? I have the original image as wBmb (check), I can crop the correct area as a rectangle (check), I have the values of the ellipse(check)...but I can`t make on the croped rectangle arean wBmp the pixels out of the ellipse area out....

Greetings and thx4all




Oct 27, 2010 at 4:26 PM

....for thoose who are intrested, I found a way....but I still have now other issues:


            foreach (var s in foundSegments)


                WriteableBitmap temp = new WriteableBitmap(selectedSnapshot);
                var c = s.Center;
                Rect tempRect = new Rect(0, 0, selectedSnapshot.PixelWidth, selectedSnapshot.PixelHeight);
                wbOverlayeyEllipseFace = new WriteableBitmap(selectedSnapshot.PixelWidth, selectedSnapshot.PixelHeight);
                wbOverlayeyEllipseFace.FillEllipseCentered(c.X, c.Y, s.Width >> 1, s.Height >> 1, Colors.White);

                temp.Blit(tempRect, wbOverlayeyEllipseFace, tempRect, WriteableBitmapExtensions.BlendMode.Mask);

                wbOverlayedRectFace = new WriteableBitmap(s.Width, s.Height);
                wbOverlayedRectFace = temp.Crop((c.X - (s.Width / 2)), (c.Y - (s.Height / 2)), s.Width, s.Height);



->Voila "wbOverlayedRectFace" is only the face with a tranparent border around...(sry for my english ;))