?
Solved

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

Posted on 2001-06-09
6
Medium Priority
?
183 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 200 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
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!

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses
Course of the Month10 days, 22 hours left to enroll

770 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