将图像并排放置
Put images side by side
如何将 VB.net 中的两张图片组合成一张大图片。它们都是 1920x1080 jpeg,我希望它能以 3840x1080 jpeg 格式出现。
像这样:我在以下位置获取这些图像:
图片 1
然后把它弄出来:图片 1 与图片 2 并排
我找到了。代码很简单,基本上是两张图片合一出来。
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()
如何将 VB.net 中的两张图片组合成一张大图片。它们都是 1920x1080 jpeg,我希望它能以 3840x1080 jpeg 格式出现。
像这样:我在以下位置获取这些图像: 图片 1
然后把它弄出来:图片 1 与图片 2 并排
我找到了。代码很简单,基本上是两张图片合一出来。
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()