Results 1 to 12 of 12

Thread: How do you...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    99
    How do you...
    1) Find out if C:\myimage.bmp is 256 colors?
    2) Find the dimensions of C:\myimage.bmp?
    ___________________________
    Chris

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    to get the dimensions:
    add a picture box (invisible)
    load the picture into the box
    msgbox picture1.picture.width & " " & picture1.picture.height
    unload the picture
    I am not sure on this but I think jpg and gif are only
    allowed 256. If that is so then knowing the ext will not tell you if they are 256 but will tell you if they are under.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Guest
    Gif's are restricted to 256 colours maximum, and JPeg's must have at LEAST 256 colours, I think i got that right.

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Yup.
    gif = 256 colors max
    jpg = 16.7 million max
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5
    Guest
    WHat's with you? Just go on the net, find the structure of a .BMP file header and read that info using: OPEN "blah.bmp" FOR BINARY AS hFile

    and some reading commands... why the picturebox? Doesn't anyone care about using useless MEGABYTES of ram using useless dll's to do stuff you could also do the easy and efficient way?

    Gerco Dries.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    99
    VB has that screwy way of using weird things... the height and width of things ARENT pixels.

    Also, BMPs may be 256 colors or not.. i want to find out how to see if they are. How do you view the header?
    ___________________________
    Chris

  7. #7
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    VB's screwy way is called Twips.
    Microsoft decided to use twips because, um, well, because... Nobody knows but Jesus.
    Anyway, I whipped up some code which sorta kinda lets you view the header of a BMP.
    The error checking is minimal, but any more and it would have to be a BMP editor.
    Try!
    Code:
    Option Explicit
    
    Enum eColors
        clrInvalid = 0      ' Unknown
        clrBlackWhite = 1   ' 1-bit, 2^1 = 2 colors (black and white)
        clr16Colors = 4     ' 4-bit, 2^4 = 16 colors
        clr256Colors = 8    ' 8-bit, 2^8 = 256 colors
        clr16BitColor = 16  ' 16-bit, 65536 colors
        clr24BitColor = 24  ' 24-bit, 16777216 colors
        clr32BitColor = 32  ' 32-bit, many colors :rolleyes:
    End Enum
    
    Private Const MINIMUM_BMP_SIZE = 66 ' Believe it or not, 66 bytes
    
    Private Const BMPID_WINDOWS = "BM"
    Private Const BMPID_OS2BMP = "BA"
    Private Const BMPID_OS2COLORICON = "CI"
    Private Const BMPID_OS2COLORPOINTER = "CP"
    Private Const BMPID_OS2ICON = "IC"
    Private Const BMPID_OS2POINTER = "PT"
    
    Private Const BMPHEADER_ID_POSITION = 1         ' The ID variable is at byte 1 of the file
    Private Const BMPHEADER_WIDTH_POSITION = 19     ' The Width variable is at byte 19 of the file
    Private Const BMPHEADER_HEIGHT_POSITION = 23    ' The Height variable is at byte 23 of the file
    Private Const BMPHEADER_COLORS_POSITION = 29    ' The Colors variable is at byte 29 of the file
    
    Function GetBitmapData(ByVal sFileName As String, lWidth As Long, lHeight As Long, BmpColors As eColors) As Boolean
        Dim btFileNum As Byte, sID As String, iColors As Integer
        On Error Resume Next
        
        btFileNum = FreeFile
        Open sFileName For Binary Access Read As btFileNum
            ' Could open file? Exit Sub
            If Not Err.Number = 0 Then Exit Function
            ' Minimal error checking:
            ' 1) Must be a valid file size
            If LOF(btFileNum) < MINIMUM_BMP_SIZE Then Exit Function
            ' 2) Must be a valid 2-byte ID
            sID = vbNullChar & vbNullChar ' Allocate 2 bytes
            Get btFileNum, BMPHEADER_ID_POSITION, sID ' Retrieve 2 bytes from file
            ' Check if the 2 bytes are valid
            If Not ((sID = BMPID_WINDOWS) Or (sID = BMPID_OS2BMP) Or (sID = BMPID_OS2COLORICON) Or _
                (sID = BMPID_OS2COLORPOINTER) Or (sID = BMPID_OS2ICON) Or (sID = BMPID_OS2POINTER)) _
                Then Exit Function
            
            ' Get Width and Height variables
            Get btFileNum, BMPHEADER_WIDTH_POSITION, lWidth
            Get btFileNum, BMPHEADER_HEIGHT_POSITION, lHeight
            
            ' Get Colors variable
            Get btFileNum, BMPHEADER_COLORS_POSITION, iColors
            
            ' Check if the color is valid, looks ugly but works!
            BmpColors = IIf((iColors = clrBlackWhite) Or (iColors = clr16Colors) Or _
                (iColors = clr256Colors) Or (iColors = clr16BitColor) Or (iColors = clr24BitColor) _
                Or (iColors = clr32BitColor), iColors, clrInvalid)
        Close btFileNum
        
        GetBitmapData = True ' Success
    End Function
    Then you could use something like...
    Code:
    Private Sub Form_Load()
        Dim lWidth As Long, lHeight As Long, BmpColors As eColors, bResult As Boolean
        Const sFileName = "C:\Windows\Clouds.bmp"
        
        bResult = GetBitmapData(sFileName, lWidth, lHeight, BmpColors)
        
        If bResult Then
            Call MsgBox(sFileName & vbCrLf & "Width: " & lWidth & " pixels." & vbCrLf & _
                "Height: " & lHeight & " pixels." & vbCrLf & "Colors: " & BmpColors & " bits.", _
                vbInformation)
        Else
            Call MsgBox(sFileName & vbCrLf & "Could not get file information." & vbCrLf & _
                "Either there was a problem opening the file, or its format is invalid.", _
                vbCritical)
        End If
    End Sub

  8. #8
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Gerco...*&^% %^$
    With todays systems who cares about the overhead of a picture box...look what the result of y2k was because someone wanted to save the 2 characters.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    99
    Thanks! That helped alot!! And I didnt know they were called "Twips", I learned something new !! YAYAYAYAY! Wowowowowoowwoowo



    d00dz!!! i l3ar|\|3|> s0m371n9 n3\/\/!!1 1337!!
    ___________________________
    Chris

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    99
    Another quick question. Would It be possible to edit the header, and add a description section? I.e. so when you load an image, it will load its description!? thanks...
    ___________________________
    Chris

  11. #11
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    About Twips and things:
    You can set the form's ScaleMode property to something other than Twips (like Pixels). The Width and Height will always be in Twips but the ScaleWidth and ScaleHeight will be whatever you selected.

    About wave headers:
    I don't think you can add a description, unless you create a new header format. Don't do that, there are too many around.
    For more information, download a document about the BMP format from http://www.wotsit.org.

    U 1337 h4x0r

  12. #12
    Guest
    I could of course tell you that the .BMP format doesn't provide for descriptions. I could also tell you to store the description in the image itself (in the pixels). That's also a cool way to store data you don't want anyone to see. Noone will ever look for it IN an image.

    But then ppl would just ***** on me for wanting to be efficient. And conserving memory by NOT using a generally useless picturebox is something completely different than assuming years will not go past 2000!

    This picturebox's only use would be to find out the width and height of a .bmp image, when it also has other uses (like displaying said image) then it's use would have been useful. In this particular instance, it would just be a wate of resources AND it's a LOT slower than just reading the header and it's not any more flexible (quite the opposite actually).

    Not all ppl use 900Mhz computers... there are still ppl (about 60% of computer users) who work on 233Mhz or lower!

    Gerco Dries.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width