但載入的圖片有時想將某些部分透明化,可以利用Bitmap的MakeTransparent來達到..
首先利用小畫家準備一張測試圖,如下所示:
部分程式碼Winform(c#)
MakeTransparent.cs
01 | using System; |
02 | using System.Collections.Generic; |
03 | using System.ComponentModel; |
04 | using System.Data; |
05 | using System.Drawing; |
06 | using System.Text; |
07 | using System.Windows.Forms; |
08 | using System.Reflection; |
09 |
10 | namespace WindowsApplication1 |
11 | { |
12 | public partial class MakeTransparent : Form |
13 | { |
14 | public MakeTransparent() |
15 | { |
16 | InitializeComponent(); |
17 | } |
18 |
19 | private void MakeTransparent_Load( object sender, EventArgs e) |
20 | { |
21 | Assembly asm = Assembly.GetExecutingAssembly(); |
22 | string name = asm.GetName().Name; |
23 |
24 | Bitmap bmp1 = new Bitmap(asm.GetManifestResourceStream(name + ".puma.bmp" )); //載入圖片資源 |
25 | this .pictureBox1.Image = bmp1; |
26 |
27 |
28 | Bitmap bmp2 = new Bitmap(asm.GetManifestResourceStream(name + ".puma.bmp" )); //載入圖片資源 |
29 | bmp2.MakeTransparent(Color.White); //將圖片白色部分透明化; |
30 | this .pictureBox2.Image = bmp2; |
31 |
32 | } |
33 | } |
34 | } |
執行結果:
评论回复