VB 里如何让PictureBox里的图片等比例适合高度

来源:百度知道 编辑:UC知道 时间:2024/05/27 06:54:53

这段代码是获取图片的高度和宽度,得到这两个数据后,你想怎么显示都可以了

Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Dim a As String, k As Single
Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type

Private Type PicInfo
PicWidth As Long
picHeight As Long
End Type

Private Function fncGetInfo(lsPicName As String) As PicInfo
'lsPicName是图片的文件名,带路径
Dim hBitmap As Long
Dim res As Long
Dim bmp As BITMAP
res = GetObject(LoadPicture(lsPicName).Handle, Len(bmp), bmp) '取得BITMAP的结构
fncGetInfo.PicWidth = bmp.bmWidth '图片的宽
fncGetInfo.picHeight = bmp.bmHeight '图片的高
End Function

引用:
Print fncG