2010-02-25 2 views
1

나는이 개 BMP 파일이 있습니다VB.NET - 생성, 크기 조정 및 추가 이미지

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

내가 원하는을 200 X 500 새 BMP 파일 만들 : 새 이미지의 하단에 footer.bmp를 추가

  1. - 다른 위치 (0, 300)
  2. ,
  3. product.bmp의 크기를 200 x 300으로 조정하고 위치를 (0, 0)

VB.NET을 사용하여 어떻게합니까?

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

oGraphics = Graphics.FromImage(oBitmap) 

...?

답변

0
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