一、从文件加载
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strFilename1 As String
Dim Pic1 As System.Drawing.Image
strFilename1 = "c:\1.png"
Pic1 = System.Drawing.Image.FromFile(strFilename1)
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
'PictureBox1.Image = Pic1
Dim Pic2 As System.Drawing.Image
Dim strFilename2 As String = "c:\2.png "
Pic2 = System.Drawing.Image.FromFile(strFilename2)
Dim b As New System.Drawing.Bitmap(Pic2.Width, Pic2.Height, PixelFormat.Format32bppArgb) '这个地方是做透明处理结果的
Dim g As Graphics = Graphics.FromImage(b)
g.Clear(Color.Transparent)
g.DrawImage(Pic2, New Rectangle(0, 0, Pic2.Width, Pic2.Height), New Rectangle(0, 0, Pic2.Width, Pic2.Height), GraphicsUnit.Pixel)
g.DrawImage(Pic1, New Rectangle(0, 0, Pic1.Width, Pic1.Height), New Rectangle(0, 0, Pic1.Width, Pic1.Height), GraphicsUnit.Pixel)
PictureBox1.Image = b
PictureBox1.BackColor = Color.Transparent
'b.Save("c:\3.png")
End Sub
'从资源文件中加载
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Pic1 As System.Drawing.Image
Pic1 = My.Resources._1
Dim Pic2 As System.Drawing.Image
Pic2 = My.Resources._2
Dim b As New System.Drawing.Bitmap(Pic2.Width, Pic2.Height, PixelFormat.Format32bppArgb) '这个地方是做透明处理结果的
Dim g As Graphics = Graphics.FromImage(b)
g.Clear(Color.Transparent)
g.DrawImage(Pic2, New Rectangle(0, 0, Pic2.Width, Pic2.Height), New Rectangle(0, 0, Pic2.Width, Pic2.Height), GraphicsUnit.Pixel)
g.DrawImage(Pic1, New Rectangle(0, 0, Pic1.Width, Pic1.Height), New Rectangle(0, 0, Pic1.Width, Pic1.Height), GraphicsUnit.Pixel)
PictureBox1.Image = b
PictureBox1.BackColor = Color.Transparent '这个地方是做透明处理结果的
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
' b.Save("c:\3.png")
End Sub