Solved

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

Posted on 2001-06-09
6
167 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

18 Experts available now in Live!

Get 1:1 Help Now