Solved

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

Posted on 2001-06-09
6
173 Views
Last Modified: 2010-08-05
Thank you!
0
Comment
Question by:turbosoft
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

740 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