VB 获取图片的像素大小的问题
为了防止用户把像索超大的图片文件存到数据库中,所以以想在图片存入DB之前得到图片的像索大小加以提示,因为相同像索的图片会因为文件类型不一样(比如相同像索的BMP就会比GIF文件大小大),所以不能以图片大小来判断 。
[解决办法]
1. 加一个Picture1
Picture1和form1的scaleMode 选 3 - pixel
Picture1的autosize = true
代码:
Private Sub Form_Load()
picture1.picture=loadpicture("*******图像的具体文件名********") '例如 "c:\lyer\liu.jpg"
msgbox "长:" & picture1.width & "宽:" & picture1.height
End Sub
2. 用api
图片框的.ScaleMode =0 ,是自定义类型
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Sub Command1_Click()
Dim cxy As RECT
Label8 = GetWindowRect(Picture1.hwnd, cxy)
Label6 = cxy.Right
Label7 = cxy.Bottom
End Sub
[解决办法]
2楼的回答太有损星星的名誉了。
[解决办法]
Private Sub Form_Load() Dim p As Picture, x, y Set p = LoadPicture("c:\1.jpg") 'ScaleMode = 3 '可以加这句,就不用除15了,根据需要选。 x = ScaleX(p.Width) \ 15 y = ScaleY(p.Height) \ 15 Debug.Print x, y Set p = Nothing End Sub
[解决办法]