将图像并排放置

时间:2016-06-24 18:49:57

标签: vb.net image jpeg

如何在VB.net中组合两个图像来创建一个大图像。它们都是1920x1080 jpegs,我希望它能以3840x1080 jpeg出现。

像这样:我将这些图片放入: image 1

enter image description here

并将其解决:图像1与图像2并排

enter image description here

1 个答案:

答案 0 :(得分:1)

我找到了。代码非常简单,基本上是一张图像中的两张图像。

        Dim ImageOne As System.Drawing.Image = Image.FromFile("img1")
    Dim ImageTwo As System.Drawing.Image = System.Drawing.Image.FromFile("img2")
    'replace path of image two with Image2.ImageUrl
    Dim NewImageHeight As Integer = If(ImageOne.Height > ImageTwo.Height, ImageOne.Height, ImageTwo.Height)
    'To calculate height of new image
    Dim NewImageWidth As Integer = ImageOne.Width + ImageTwo.Width
    ' width of new image



    Dim NewImageBmp As New Bitmap(NewImageWidth, NewImageHeight, Imaging.PixelFormat.Format32bppArgb)
    ' you can change the bpp as per your requirment. Size of image directly propotionate to bpp of image

    Dim NewImageGrx As Graphics = System.Drawing.Graphics.FromImage(NewImageBmp)


    NewImageGrx.DrawImageUnscaled(ImageOne, 0, 0)
    'draw first image at coordinate 0,0 
    NewImageGrx.DrawImageUnscaled(ImageTwo, ImageOne.Width, 0)
    'draw second image at coordinate image1.width,0
    Dim CombineImage As String = Guid.NewGuid().ToString() + ".jpg"
    NewImageBmp.Save("output file", ImageFormat.Jpeg)
    ' saving combined image. You can specify the ImageFormat as per your requirment.

    'disposing objects after use
    ImageOne.Dispose()
    ImageTwo.Dispose()


    NewImageBmp.Dispose()
    NewImageGrx.Dispose()