问题
The MaskColor
property in VB 6.0 is used to remove the background color of an Image
. How might I do the same in C#?
回答1:
You can use MakeTransparent(Color color) for the bitmap image. example:
//convert the red color in the image into transparent.
((Bitmap)BackgroundImage).MakeTransparent(Color.Red);
回答2:
I don't think there is any direct equivalent.
I've made it work in the past by using the ColorMap class to map my background color to Color.Transparent. Then I create an ImageAttributes object and call the SetRemapTable() function and pass it my ColorMap. Then you redraw the image by passing the ImageAttributes to the DrawImage method.
Edit:
Jalal posted a much easier way for a solid color. I took a closer look at the code where I was using the method above, I was mapping more than one shade of the same base color to transparent.
来源:https://stackoverflow.com/questions/7129956/what-is-equivalent-of-vb6-0s-maskcolor-property-in-c-sharp