您可能需要计算你要多大的形象是,然后创建它的一个缩略图:
Friend Function GetImageThumb(ByVal orgBmp As BitMap,
ByVal w as Int32, h as Int32) As Bitmap
Dim thumb As New Bitmap(w, h)
Using g As Graphics = Graphics.FromImage(thumb)
g.DrawImage(orgBmp , 0, 0, w + 1, h + 1)
End Using
Return thumb
End Function
更重要的也许是缩放。确定是否要根据宽度或高度来调整大小,然后基于此计算新大小。
' get new Height Scaled from a set Width:
Friend Function ScaledHeight(ByVal w As Integer, orgSize as Size) As Integer
Dim scale As Single = CSng(orgSize.Height/orgSize.Width)
Return CInt(w * scale)
End Function
' get new Width scaled from the Height:
Friend Function ScaledWidth(ByVal h As Integer, orgSize as Size) As Integer
Dim scale As Single = CSng(orgSize.Width/orgSize.Height)
Return CInt(h * scale)
End Function
看RAW图像,找出你希望它是新的大小,然后通过缩放宽度或高度(通常高度,对我来说),然后使用创建一个确定的拇指大小使用该新尺寸的缩略图。
编辑
它是不是真正的“固定”的,除非你想显示所有图像具有非常相同的尺寸,这是不常见的情况。当屏幕具有与图像不同的高宽比(W:H)时,缩放比较重要。
对于屏幕的60%大小(伪代码,你就必须努力一些东西出来):
Dim bmp as Bitmap = New Bitmap(My.Resources.ground_floor_plan)
Dim orgSize As Size = bmp.Size
' scale to 60% of width
Dim newWidth As Integer = (thisForm.Width * .6)
' maybe:
'Dim newWidth As Integer = (My.Computer.Screen.WorkingArea.Width * .6)
Dim newWidth As Int32 = ScaledHeight(newWidth, orgSize)
Dim thumb as Bitmap = GetImageThumb(bmp, newWidth, newHeight)
cm.MarkerImage = thumb
objects.Markers.Add(cm)
bmp.Dispose
什么是“厘米”?什么类型的对象?......或最终显示在/上的图像是什么? – Plutonix
对不起,它只是'customImageOverlay'类的一个声明:)我只是将它作为* overlay *添加到地图上。这是另一种可能的方式,而不是创建新的表单并使用按钮,这是您昨天回答的问题。 – AdorableVB