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
Solved

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

Posted on 2001-06-09
6
171 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

860 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