我想將圖像大小調整爲4x4像素圖像在vb.net。使用Graphics.DrawImage調整圖像尺寸結果尺寸調整不正確
使用互聯網,我得到這個代碼:
Public Function ResizeImage(ByVal image As Image) As Image
Try
Dim newWidth = 4
Dim newHeight = 4
Dim newImage As New Bitmap(newWidth, newHeight)
newImage.SetResolution(100, 100)
Using graphicsHandle As Graphics = Graphics.FromImage(newImage)
graphicsHandle.InterpolationMode = InterpolationMode.HighQualityBicubic
graphicsHandle.DrawImage(image, 0, 0, newWidth, newHeight)
End Using
Return newImage
Catch ex As Exception
Return image
End Try
End Function
原文:
用Photoshop(調整它的真正途徑)調整大小:
使用InterpolationMode.Bilinear
使用InterpolationMode.HighQualityBicubic
問題是什麼?
'趕上例外:返回圖像'是一個可能的問題。我建議你暫時刪除'Try/Catch'塊(和'Return image')來查看你的代碼是否會拋出任何異常。目前,您不知道它是否可以導致它返回相同的圖像(如果這是您正在經歷的)。 –
@VisualVincent它與它無關,我還用一個msgbox來檢查它是否捕獲任何錯誤,它不會 –
...所以*真正的問題不是大小不正確 - 它們確實看起來像是4x4 - 而是你不喜歡插值,並認爲PhotoShop是唯一的「正確的方式」? – Plutonix