I’m currently coding a simple image manipulator with C# Bitmaps und Graphics. I’m using a costum transparent elemt and it works fine. in my Draw-Method I update the control by drawing to set image:
ImageAttributes attr = new ImageAttributes();
attr.SetColorKey(this.transpKey, this.transpKey);
Rectangle dstRect = new Rectangle(0, 0, this.image.Width, this.image.Height);
e.Graphics.DrawImage(this.image, dstRect, 0, 0, this.image.Width, this.image.Height, GraphicsUnit.Pixel, attr);
e.Graphics.Dispose();
Now I need a function to erase some pixels. Using a Form and drawing on BackgroindImage I can “erase” pixels by using the TransparencyKey-Prperty. But this proterty doesn’t exists in my costum control. That’s the reason why I used “attr.SetColorKey(this.transpKey, this.transpKey);”, but there is the problem. It just makes the pixel transparent and the pixels underliing will be visible.
Does anyone know how to force C# to replace pixels instead of leaving them? Or does anyone know a solution for my problem?
Thank you very much for reading, thinking and maybe helping.
//Edit:
OK, now I found out that I can use “e.Graphics.CompositingMode = CompositingMode.SourceCopy;” to set that the pixel shall be replaced. But after that the transparency is destroyed. And the result is the same. Nothing erased. Any solutions?
To provide my solution officially: I solved it by using several layers. Not clean but it works.