我要放大面板内部的图片框的图像。基本上,这是一个Radar模拟器,我需要在图片框上显示地图并将其缩放到100 NM至1 NM的范围。缩放值由HScrollBar决定(Min-1,Max-100,对应于NM)。如果HScrollbar值为100(平均100 NM),则显示不带缩放的完整图像,而HScrollbar值为1(平均1 NM)时,图像需要放大到图片中心的1/100倍。
在我现在的代码中,我增加了picturebox控件的大小,然后设置其Left和Top属性以使其居中。图片尺寸为577 X 577,图片框尺寸等于屏幕尺寸(即最大化)。但是问题是,我只能将其放大到2.5倍。超过2.5倍的缩放速度使其变得极其缓慢,有时还会绘制错误图像,即图片框中的红色X标记。
If pb.Image IsNot Nothing Then
'calculate the new size from the original image size
Dim nWidth As Integer = CInt((panel1.Width + (100 * panel1.Width / frmLDA.HSRange.Maximum) * (frmLDA.HSRange.Maximum - _scale)))
Dim nHeight As Integer = CInt((panel1.Height + (100 * panel1.Height / frmLDA.HSRange.Maximum) * (frmLDA.HSRange.Maximum - _scale)))
newWidth = nWidth
newHeight = nHeight
'make sure you do not try to create a new bitmap that has a width or height of 0
If nWidth > 0 And nHeight > 0 Then
'create a new bitmap at the new size
Using bmp As New Bitmap(nWidth, nHeight)
'create a graphics object for the new bitmap
Using g As Graphics = Graphics.FromImage(bmp)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(OriginalImage, 0, 0, nWidth, nHeight)
End Using 'disposes the graphics object
pb.Image.Dispose() 'dispose the old bitmap that was assigned to the image property
pb.Image = New Bitmap(bmp) 'assign a copy of the new Bitmap
pb.ClientSize = pb.Image.Size 'reset the size of the picturebox
pb.Left = CInt(panel1.Width / 2 - pb.Width / 2)
pb.Top = CInt(panel1.Height / 2 - pb.Height / 2)
End Using 'disposes the Bitmap
End If
End If
在没有实际增加图片框大小的情况下,是否有任何方法可以平滑缩放图像,从而不会遇到任何错误?任何帮助将不胜感激。谢谢。