我需要在 C# VS2013 中删除位图的黑色背景颜色。
就像我在画布上画一些点一样。这canvas是黑色的,我只需要将画布更改为透明的同时保持其上的彩色点不做任何改变。
我在以下位置得到了解决方案:如何从位图中删除白色背景色 https://stackoverflow.com/questions/15375453/how-to-remove-white-background-color-from-bitmap
Bitmap capcha = new Bitmap(@"C:/image.png");
capcha.MakeTransparent(Color.Black);
但是,背景仍然是灰色的,就像雾一样覆盖了图像上的点。
如何去除它?
UPDATE我使用了代码:
ImageAttribute imageAttribute = new ImageAttribute();
imageAttribute.SetGamma(0.5f, ColorAdjustType.Bitmap);
gr.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height),
0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imageAttribute );
我得到同样的事情。
绘制图像的 C# 代码的更多更新:
System.Drawing.Bitmap canvasImage = new System.Drawing.Bitmap(xSize, ySize, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
canvasImage.MakeTransparent(Color.Black);
Graphics g = Graphics.FromImage(canvasImage);
System.Drawing.Bitmap tempImage = myDrawImageFunction(myPoints);
g.Clear(Color.Transparent); // this only give me an empty image without any points on it. But, if I uncomment it, I will have an image with black background.
// my understanding about g.DrawImage() is to draw points on tempImage
// after clearing the background. But, the image still have a foggy covering on the image.
g.DrawImage(tempImage, new System.Drawing.PointF(x_position, y_position));
我想在“tempImage”上绘制任何点之前有一个透明的背景。
示例图像的背景需要删除,但图像上的彩色点需要保留而不进行任何更改。