2011-03-10 99 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