What is equivalent of VB6.0's MaskColor property in C#

北慕城南 提交于 2020-01-15 08:57:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!