2017-06-13 104 views
0

是否存在将图像保存为集合的简单方法210px高度但宽度将成比例。例如。如果图像自然是420 x 600的话,那就调整/另存为210 X 300。我正在使用的代码是VB和当前设置保存为210x210 ..将图像保存为120高度x比例宽度 - VB

Dim returnImage As System.Drawing.Image = Image.FromFile("D:\domains\example.com\httpdocs\catalog\images\" & imageFilename) 
    Dim thumb As System.Drawing.Image = FixedSize(returnImage, 210, 210) 

回答

1

我相信你想要什么要做的是保持长宽比,这是我使用的代码:

Public Function ScaleImage(ByVal OldImage As System.Drawing.Image, ByVal TargetHeight As Integer, ByVal TargetWidth As Integer) As System.Drawing.Image 

    Dim NewHeight As Integer = TargetHeight 
    Dim NewWidth As Integer = NewHeight/OldImage.Height * OldImage.Width 

    If NewWidth > TargetWidth Then 
     NewWidth = TargetWidth 
     NewHeight = NewWidth/OldImage.Width * OldImage.Height 
    End If 

    Return New Bitmap(OldImage, NewWidth, NewHeight) 

End Function 
+0

非常有帮助谢谢。我不需要IF语句,因为我希望图像的高度为210,但对宽度没有限制,所以我将其解决了。非常感谢! – Eggybread

相关问题