|
-
Feb 12th, 2005, 08:26 PM
#1
Thread Starter
Fanatic Member
Get BMP width and height
how can I get a BMP's width and height threw API?
-
Feb 12th, 2005, 11:25 PM
#2
Re: Get BMP width and height
I think you can do it using this GetBitmapBits API
HTH
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 13th, 2005, 11:25 AM
#3
Re: Get BMP width and height
If you don't want to load all the bitmap data, then you could use the alternative function GetObject
VB Code:
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" ( _
ByVal hObject As Long, _
ByVal nCount As Long, _
lpObject As Any _
) As Long
Private Type BITMAP '14 bytes
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Dim bm As BITMAP
GetObject Picture1.Image, Len(bm), bm
...
-
Feb 13th, 2005, 04:00 PM
#4
Re: Get BMP width and height
What do you need GetObject for if image is already loaded in the picturebox - simply get ScaleWidth/Height:
VB Code:
Private Sub Command1_Click()
'=============================
Dim pct As Picturebox
Set pct = Me.Controls.Add("VB.Picturebox")
pct.Autosize = Tue
pct.Picture = LoadPicture(App.Path & "\my_image.bmp")
Debug.Print pct.ScaleWidth
Debug.Print pct.ScaleHeight
Set pct = Nothing
End Sub
-
Feb 13th, 2005, 04:04 PM
#5
Thread Starter
Fanatic Member
Re: Get BMP width and height
all these examples use a picture box. i need to get width/height without picture box.
-
Feb 13th, 2005, 06:16 PM
#6
Re: Get BMP width and height
What do you need GetObject for if image is already loaded in the picturebox - simply get ScaleWidth/Height:
Sure, if you want to do it the easy way
Make sure you're using pixels however
VB Code:
wid = Picture1.ScaleX(Picture1.ScaleWidth, Picture1.ScaleMode, vbPixels)
hgt = Picture1.ScaleY(Picture1.ScaleHeight, Picture1.ScaleMode, vbPixels)
But now we're not allowed to use a picture box
VB Code:
Option Explicit
Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" ( _
ByVal hInst As Long, _
ByVal lpsz As String, _
ByVal un1 As Long, _
ByVal n1 As Long, _
ByVal n2 As Long, _
ByVal un2 As Long _
) As Long
Const IMAGE_BITMAP = 0
Const IMAGE_ICON = 1
Const IMAGE_CURSOR = 2
Const LR_LOADFROMFILE = &H10
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" ( _
ByVal hObject As Long, _
ByVal nCount As Long, _
lpObject As Any _
) As Long
Private Type BITMAP '14 bytes
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Sub GetBMP(strImageFile As String)
Dim hWndIMG
Dim bm As BITMAP
hWndIMG = LoadImage(0, strImageFile, 0, 0, 0, LR_LOADFROMFILE)
GetObject hWndIMG, Len(bm), bm
Debug.Print bm.bmWidth, bm.bmHeight
End Sub
-
Feb 13th, 2005, 10:56 PM
#7
Re: Get BMP width and height
 Originally Posted by psychotomus
all these examples use a picture box. i need to get width/height without picture box.
Yes, but in my sample I create picturebox control at run time, it's hidden and may get removed from controls collection immediately after reading width/height so I don't see any reasons not to use it - it's simple, fast and clean:
VB Code:
Option Explicit
Dim intPicWidth As Integer
Dim intPicHeight As Integer
Private Sub Command1_Click()
'=============================
Dim pct As Picturebox
Set pct = Me.Controls.Add("VB.Picturebox", "pctTemp")
pct.Autosize = Tue
pct.Picture = LoadPicture(App.Path & "\my_image.bmp")
intPicWidth = pct.ScaleWidth
intPicHeight = pct.ScaleHeight
Me.Controls.Remove "pctTemp"
Set pct = Nothing
End Sub
Last edited by RhinoBull; Feb 13th, 2005 at 10:59 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|