2009-12-14 53 views

回答

2

在下面的代码首先加载图像,然后用新的宽度和高度创建一个新的图像,抓住图形从它对象最后得出旧图像投影到新的图像。我们得出的旧有形象上使用旧图像的尺寸,新的形象,但由于新的图像较小,其余将被关闭的画布。

Private Shared Sub CropImage(ByVal inputImagePath As String, ByVal outputImagePath As String, ByVal newHeight As Integer) 
    Using oldImage = System.Drawing.Image.FromFile(inputImagePath) 
     Using NewImage As New System.Drawing.Bitmap(oldImage.Width, newHeight) 
      Using G = Graphics.FromImage(NewImage) 
       G.DrawImage(oldImage, 0, 0, oldImage.Width, oldImage.Height) 
       NewImage.Save(outputImagePath, System.Drawing.Imaging.ImageFormat.Jpeg) 
      End Using 
     End Using 
    End Using 
End Sub 
+0

+1这是非常有用的,感谢您张贴您的解决方案 – Hallaghan 2012-02-27 17:19:20