有哪些方法可以调整图片框中图像的缩放距离?
我将图片从文件加载到图片框,这是我的代码...
Dim fs As FileStream
OpenFileDialog1.Filter = "JPG files (*.jpg)|*.jpg|" & "BMP Files (*.bmp)|*.bmp|" _
& "TIF Files (*.tif)|*.tif|" & "PNG Files (*.png)|*.png|" & "ALL Files (*.*)|*.*"
OpenFileDialog1.Title = "Select an Image File"
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
currentfilename = OpenFileDialog1.FileName
If currentfilename.ToUpper.EndsWith(".JPG") Or _
currentfilename.ToUpper.EndsWith(".BMP") Or _
currentfilename.ToUpper.EndsWith(".TIF") Or _
currentfilename.ToUpper.EndsWith(".PNG") Then
If Not (Pic.Image Is Nothing) Then
Pic.Image.Dispose()
Pic.Image = Nothing
End If
fs = New FileStream(currentfilename, IO.FileMode.Open, IO.FileAccess.Read)
Pic.Image = Image.FromStream(fs)
original = Pic.Image
End If
End If
然后我使用此代码调整缩放距离...
If original Is Nothing Then
Exit Sub
End If
If Not converted Is Nothing Then
converted.Dispose()
End If
If Not zoomImage Is Nothing Then
zoomImage.Dispose()
End If
zoomImage = New Bitmap(original, _
(Convert.ToInt64(original.Width * (ZoomValue) / 100)), _
(Convert.ToInt64(original.Height * (ZoomValue / 100))))
converted = Graphics.FromImage(zoomImage)
converted.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
Pic.Image = Nothing
Pic.Image = zoomImage
如果我只是使用小图片,但是如果我有一个大图像,如果我有一个大图像,我就不会有这个问题,例如,一个图像i&#39 ; m显示是一个1.5MB的TIFF文件,大小为33000 x 4000.我只想调整图像的缩放级别,我不需要任何其他东西,比如在图像上绘图,更改像素的颜色或任何其他操纵。
答案 0 :(得分:0)
查看distance(from:to:)
,表明您可能需要处理面板/图片框的Paint事件
你可以这样做:
Private Sub Pic_Paint(sender As Object, e As PaintEventArgs) Handles Pic.Paint
Dim newRect = New Rectangle(0, 0, _
(Convert.ToInt64(original.Width * (ZoomValue / 100))), _
(Convert.ToInt64(original.Height * (ZoomValue / 100))))
e.Graphics.DrawImage(u, New Rectangle(0, 0, Pic.Width, Pic.Height), _
newRect, GraphicsUnit.Pixel)
End Sub