2011-03-10 98 views
0

我想绘制点透明的图像上的点。就像我可以看到他们在哪个区域一样。有没有什么办法在C#.net平台上这样做?在表单上绘制点

谢谢。

回答

4

这是一种方法。

Image bitmap = new Bitmap(100, 100); // sample image, load your real image from file here 
using (var g = Graphics.FromImage(bitmap)) 
{ 
    g.FillRectangle(Brushes.Red, new Rectangle(0, 0, bitmap.Width, bitmap.Height)); // Just to fill the background on the sample image, remove this 

    var transparentColor = Color.FromArgb(127, Color.Blue); // Create a semitransparent color 
    using(Brush brush = new SolidBrush(transparentColor)) 
    { 
     // Create the dot 
     g.FillEllipse(brush, new Rectangle(10, 10, 25, 25)); 

     // Create another dot 
     g.FillEllipse(brush, new Rectangle(25, 15, 25, 25)); 
    } 
} 

myPictureBox.Image = bitmap; // display the image in an Imagebox (optional, you might use your image somewhere else) 
+0

这件事情很好.. bt你能告诉我它究竟是如何创建透明效果?是它的声明“color.fromargb”。也如果我想不使用任何位图有没有办法? – olive 2011-03-11 05:41:16

+0

@olive,yes ['FromArgb'](http://msdn.microsoft.com/en-us/library/system.drawing.color.fromargb.aspx)创建一个颜色,'127'是alpha值(透明度通道)。还有其他重载用于从'a,r,g,b'单独创建颜色,请参阅所有重载的链接。 – 2011-03-11 07:32:40

+0

@olive,你可以使用任何其他图像,而不是位图,我用'位图'类型更新了我的答案。 – 2011-03-11 07:33:48