我试图创建一个调整图像大小并将它们加载到图片框的函数......
到目前为止,我已经这样做了:
Function ResizeImage(Picture As ImageFile, Width As Integer, Height As Integer) As ImageFile
Dim ratioWidth, ratioHeight, ratio As Double
Dim newWidth, newHeight As Integer
Dim img As ImageFile
Set img = Picture
'Calgulate AspectRatio
ratioWidth = (Width / Picture.Width)
ratioHeight = (Height / Picture.Height)
'Choose the smaller ratio
If ratioWidth > ratioHeight Then
ratio = ratioHeight
Else
ratio = ratioWidth
End If
'Calgulate newWidth and newHeight
newWidth = Picture.Width * ratio
newHeight = Picture.Height * ratio
'Return resized image
ResizeImage = img.ARGBData.Picture(newWidth, newHeight)
End Function
函数称为:
picResim.Picture = LoadPicture(PicturePath) 'Show picture first
Set PrintImg = New ImageFile 'Create a background picture
PrintImg.LoadFile PicturePath 'to process on
picResim.Picture = ResizeImage(PrintImg, 40, 30) 'Show resized picture
但是正如您所看到的,我需要进行大量调试,我做错了什么我该如何解决这个问题?