How to fill bitmap with color #00000000
-
Friday, January 27, 2006 10:16 AM
Hello.
I want to fill bitmap with color #00000000.
DrawingVisual visual = new DrawingVisual();
DrawingContext context = visual.RenderOpen();
using( context ) {
Brush brush = new SolidColorBrush( Color.FromArgb( 0, 0, 0, 0 ) );
RectangleGeometry geometry = new RectangleGeometry( new Rect( 0, 0, 100, 100 ) );
GeometryDrawing drawing = new GeometryDrawing( brush, null, geometry );
context.DrawDrawing( drawing );
}
renderTargetBitmap.Render( visual );But, this code do not fill rectangle because brush.Color.A ( alpha channel ) is 0.
If brush.Color.A is 0xff, this code fills rectangle with black.Please tell me how to fill bitmap with color #00000000.
All Replies
-
Friday, January 27, 2006 7:30 PMModerator
Perhaps I don't understand the question. What are you expecting to happen when you use #00000000 that's not happening?
-
Sunday, January 29, 2006 6:35 PM
Well, #ff000000 is black, so that's expected
#00000000 is completley transparent, so I'm not sure what you expect to see. Set the alpha property to something like #88, and specify a 32-bit bitmap (because only 32-bit bitmaps support transparency), and you'll have a partially-transparent black bitmap.
-
Monday, January 30, 2006 12:01 AM
The behavior is more subtle, actually. When you call DrawRectangle (or DrawGeometry with a rectangle, or really any drawing methods) the system blends the figure with the background using the fill and stroke brushes. If your fill brush is fully transparent, then the blending operation doesn't have any effect on the output. So hYam is right -- drawing with a transparent brush doesn't draw anything.
In addition, the RenderTargetBitmap.Render method does not clear the output bitmap before rendering, to allow for cumulative effects for successive calls to the method. The idea is that for opaque output bitmaps you can do your own clearing by drawing an opaque rectangle the size of the bitmap. However, for transparent output bitmaps you need another mechanism. I don't believe any such mechanism is exposed, unfortunately, so unless the bitmap is transparent black on creation there may not be a way to do this. I'll double check with the imaging team to be sure.

