Fill Extensions that only modify one channel

Sep 29, 2010 at 8:18 AM

I really appreciate the work you've done. I'm looking for a way to fill an ellipse in a bitmap but only affect one channel. For example change the alpha but leave r, g and b whatever color the source bitmap was. Something like this,

writeableBmp.FillEllipseCentered(2, 2, 8, 5, Color.FromArgb(0, "bmp.Red", "bmp.Blue", "bmp.Green");

This psuedo code would make the elipse area transparent but leave r, g and b whatever colors they where which is different from Colors.Transparent which makes a, r, g and b all = 0. Any ideas on how this could be done?

I noticed in WriteableBitmapFillExtensions.cs there is a section called // Draw line. Maybe changing that to something like this?:

pixels[i + uh] = Color.FromArgb(a, pixels[i + uh].red, pixels[i + uh].green, pixels[i + uh].blue)

Thanks,

Jason

Coordinator
Sep 29, 2010 at 9:23 AM

Hi Jason,

Such functionality is too special, so I won't include something like this in the library. I also don't have time soon. However, feel free to use the source and modify it as you need it.

BUT, what you are describing is commonly implemented via Blending. You would draw the ellipse to one bitmap and then blend it with original bitmap. See the Blend method and the mode None. But it uses all channels at moment and doesn't support the modification of only one channels at the moment. This can be extended of course. 

 

- Rene Schulte