Solved

How can I get the size of a bitmap using APIs?

Posted on 2001-06-09
6
168 Views
Last Modified: 2010-08-05
Thank you!
0
Comment
Question by:turbosoft
6 Comments
 
LVL 5

Expert Comment

by:jklmn
ID: 6170701
Hi,

Why not do this in pear VB:

'With Image1.Strech = False, Image1.visible = False
Private Sub Command1_Click()
Image1.Picture = LoadPicture("c:\test\test.bmp")
'Image1.Picture = Image2.Picture
Print "Bitmap width = " & Image1.Width
Print "Bitmap height = " & Image1.Height
End Sub
0
 
LVL 3

Accepted Solution

by:
wpsjr1 earned 50 total points
ID: 6172089
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

Private Declare Function GetObjectAPI& Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any)

Private Declare Function DeleteObject& Lib "gdi32" (ByVal hObject As Long)

Private Const IMAGE_BITMAP = 0
Private Const LR_LOADFROMFILE = &H10

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 Sub BMPInformation(ByRef sFileName as string, ByRef bmp as BITMAP)
  Dim objHandle as Long

  objHandle = LoadImage(0, sFileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)

  GetObjectAPI objHandle, Len(bmp), bmp

  DeleteObject objHandle
End Sub

' usage -------------------------

  dim bmp as BITMAP
  BMPSize "c:\mypic.bmp", bmp

  Debug.Print bmp.bmWidth & "<- Width"
  Debug.Print bmp.bmHeight & "<- Height"

' -------------------------------

' Its probably faster to use Binary mode and open the bmp.  GET a bitmapfileheader and bitmapinfoheader.  The bitmapinfoheader has the width/height too.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6172277
Private Sub Form_Load()
Dim pic As StdPicture
Set pic = LoadPicture("C:\WINDOWS\1stboot.bmp")
Debug.Print pic.Height
Debug.Print pic.Width
End Sub
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Expert Comment

by:glass_cookie
ID: 6173043
Hi!

I'm not sure if you're looking for the filesize of the bitmap or the height and width of the bitmap.

But just in cse you mean filesize, just do this:

MsgBox FileLen("C:\MyBitmap.bmp")

Where "C:\MyBitmap.bmp" is the filepath of your bitmap file, FileLen() would return a value of the filepath.

That's it!

glass cookie : )

PS If this is N.A. then just ignore me : )
0
 

Author Comment

by:turbosoft
ID: 6184867
How can I do it using GetBitmapDimensionEx?The value of

size.cx is zero after the function is called?Why?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6185810
The GetBitmapDimensionEx function retrieves the dimensions of a bitmap. The retrieved dimensions MUST have been set by the SetBitmapDimensionEx function.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now