开发者

VB.NET - Creating, resizing and appending images

I have two bmp files:

  1. footer.bmp: 200 x 200
  2. product.bmp: 1000 x 1000

I want to create a new bmp file with 200 x 500:

  1. Append the footer.bmp into the bottom of the new image - position (0, 300)
  2. Resize the product.bmp to 200 x 300 and position into (0,开发者_C百科 0)

How do I do this using VB.NET?

Dim oBitmap As New Bitmap(200, 500)
Dim oGraphics As Graphics

oGraphics = Graphics.FromImage(oBitmap)

... ?


Dim Path As String = "C:\Delivery\"
Dim Height As Integer = 400

Using oFooter As System.Drawing.Image = Drawing.Image.FromFile(Path + "Footer.png")

    Dim Width As Integer = oFooter.Width

    Using oBitmap As New Bitmap(Width, Height)

        Using oGraphic As Graphics = Graphics.FromImage(oBitmap)

            Using oBrush As New SolidBrush(Color.White)
                oGraphic.FillRectangle(oBrush, 0, 0, Width, Height)
            End Using

            oGraphic.DrawImage(oFooter, 0, 300)

            Using oProduto As System.Drawing.Image = Drawing.Image.FromFile(Path + "Produto.png")

                Dim pWidth As Integer = oProduto.Width
                Dim pHeight As Integer = oProduto.Height

                If pWidth > Width Then
                    pHeight = CInt(pHeight * Width / pWidth)
                    pWidth = Width
                End If

                If pHeight > Height Then
                    pWidth = CInt(pWidth * Height / pHeight)
                    pHeight = Height
                End If

                Dim x As Integer = CInt((Width - pWidth) / 2)
                Dim y As Integer = CInt((Height - oFooter.Height - pHeight) / 2)

                oGraphic.DrawImage(oProduto, x, y, pWidth, pHeight)

            End Using

            oBitmap.Save(Path + "Final.jpg", Imaging.ImageFormat.Jpeg)

        End Using

    End Using

End Using
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜