vb.net 两个PNG文件叠加处理方式

   一、从文件加载
 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

 
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值