2014-01-17 112 views
0

我们下载或创建的所有图片都有不同的尺寸,其中大部分时间不适合我们创建的应用。
有没有办法强制图片到出现例如A4尺寸?将图片强制为固定尺寸

对于我的具体问题,
enter image description here
这是应用程序的整个窗口,但画面的底部,这是为什么,我想设定的界限更有可能进一步延伸,它强制调整到屏幕的60%

这是我如何调用图像

Dim cm As New customImageOverlay(mainMap.Position) 
cm.MarkerImage = New Bitmap(My.Resources.ground_floor_plan) 
' before I make it appear to the map I want to do something like this 
' cm.size = form.clientrectagle - 40% - just something in my mind.. 
    objects.Markers.Add(cm) 
' this is at form load event, I am just adding the image as an overlay 
' so there are no pictureboxes 
+0

什么是“厘米”?什么类型的对象?......或最终显示在/上的图像是什么? – Plutonix

+0

对不起,它只是'customImageOverlay'类的一个声明:)我只是将它作为* overlay *添加到地图上。这是另一种可能的方式,而不是创建新的表单并使用按钮,这是您昨天回答的问题。 – AdorableVB

回答

1

您可能需要计算你要多大的形象是,然后创建它的一个缩略图:

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 
+0

如何在添加图像之前调用此选项?在'objects.Markers.add(cm)'..之前没有像'set image to 1024 x 640'这样的东西吗? – AdorableVB

+0

请参阅编辑粗略。在某些情况下,您可能需要根据是要显示大量图像还是使用更多的屏幕空间来调整其他方式。 – Plutonix

+0

我应该在哪里声明orgSize? – AdorableVB