WriteableBitmap dont let me draw a Rectangle (AccessViolationException)

220 Views Asked by At

I have a wpf UserControl that should draw a little chart. The UserControl is rendered multiple times within a grid. Unfortunately I get a AccessViolation Exception when the UserControl is visible more than once.

The AccessViolation Exception is thrown after some other drawing (only FillRectangle calls)..

This is how the code looks:

var bmp = BitmapFactory.New(200, 30);
using (bmp.GetBitmapContext())
{
    bmp.FillRectangle(0, 0, (int)bmp.Width , (int)bmp.Height , MyColors.WhiteSmoke);

    // .. some calculations and rectangle drawings

    bmp.FillRectangle(vX1, vY1, vX2, vY2, Colors.RosyBrown);  //<- Violation Exception
}

The strange thig is: When I change the last line to:

bmp.FillRectangle(vX1, vY1, vX2, vY2, Color.FromArgb(100, Colors.RosyBrown.R, Colors.RosyBrown.G, Colors.RosyBrown.B));

everything works fine.

This is the first time I am using WritableBitmap. Am I doing something wrong?

0

There are 0 best solutions below