■■■

2016年4月3日日曜日

PictureBoxの特定の色を透明色として設定する方法

PictureBoxの特定の色を透明色として設定する方法
VB.NET

Dim bmp As New Bitmap("C:\test\maketransparent1.png")
'透明色
bmp.MakeTransparent(Color.Black)

Dim backBmp As New Bitmap("C:\test\maketransparent2.png")

Dim g As Graphics = Graphics.FromImage(backBmp)
g.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height)
g.Dispose()
bmp.Dispose()

PictureBox1.Image = backBmp
C#
Bitmap bmp = new Bitmap(@"C:\test\maketransparent1.png");
//透明色
bmp.MakeTransparent(Color.Black);

Bitmap backBmp = new Bitmap(@"C:\test\maketransparent2.png");

Graphics g = Graphics.FromImage(backBmp);
g.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height);
g.Dispose();
bmp.Dispose();

PictureBox1.Image = backBmp;

■■■