dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: BMP Information Program Size

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    BMP Information Program Size

    [Originally posted by Miner=(]

    hi there expert

    My problem is this I want a program that will open up files like File.ess (which has a BMP header when you open it in hex editor BM etc. etc. after the BMP is done comes important information that tells where this BMP should be placed.. Since i cant use Hex / Ascii cause the picture is always bigger or smaller in size

    So.. can you make a example that will when file is opened

    get the file size of the bmp...
    So than simply from the total size - bmp file size = you get the important imformation and bmp file :\

    I tried many ways on looking on PSC but they all use the cheap file size of the file method

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:BMP Information Program Size

    [Originally posted by m.posseth@work]

    well here is a class i once wrote to get the size of pictures

    comments are in dutch ( my native language )
    but i think they are not really necessary

    if you need the comments i can translate them for you but i hope it is clear what it does




    Option Explicit
    'alleen de eerste X ? bytes van de file worden in de byte array
    'ingelezen dus Buffersize=X ? een hoger nummer zou meer geheugen verbruiken
    'en langzamer zijn , een lager getal als 65535 zou kunnen betekenen dat we niet alle JPEG files
    'kunnen decoderen dus voel je vrij om wat te experimenteren
    Private Const BUFFERSIZE As Long = 65535
    ' image type enum
    Public Enum eImageType
    itUNKNOWN = 0
    itGIF
    itJPEG
    itPNG
    itBMP
    End Enum
    ' private member variabelen
    Private m_Width As Long
    Private m_Height As Long
    Private m_Depth As Byte
    Private m_ImageType As eImageType


    Friend Property Get Width() As Long
    Width = m_Width
    End Property

    Friend Property Get Height() As Long
    Height = m_Height
    End Property

    Friend Property Get Depth() As Byte
    Depth = m_Depth
    End Property

    Friend Property Get ImageType() As eImageType
    ImageType = m_ImageType
    End Property
    Friend Sub ReadImageInfo(sFileName As String)
    On Local Error Resume Next
    ' Byte array buffer
    Dim bBuf(BUFFERSIZE) As Byte
    ' Open file number
    Dim iFN As Integer

    ' default values
    m_Width = 0
    m_Height = 0
    m_Depth = 0
    m_ImageType = itUNKNOWN

    ' laad de file
    iFN = FreeFile
    Open sFileName For Binary As iFN
    Get #iFN, 1, bBuf()
    Close iFN

    If bBuf(0) = 137 And bBuf(1) = 80 And bBuf(2) = 78 Then
    ' dit is een PNG file

    m_ImageType = itPNG

    ' bit depth
    Select Case bBuf(25)
    Case 0
    ' greyscale
    m_Depth = bBuf(24)

    Case 2
    ' RGB encoded
    m_Depth = bBuf(24) * 3

    Case 3
    ' Palette based, 8 bpp
    m_Depth = 8

    Case 4
    ' greyscale met alpha
    m_Depth = bBuf(24) * 2

    Case 6
    ' RGB encoded met alpha
    m_Depth = bBuf(24) * 4

    Case Else
    'de waarde is buiten de normale range
    'we gaan ervanuit dat dit geen geldig formaat is !
    m_ImageType = itUNKNOWN

    End Select

    If m_ImageType Then
    'we hebben de waarde kunnen bepalen

    ' de breedte
    m_Width = Mult(bBuf(19), bBuf(18))

    ' de hoogte
    m_Height = Mult(bBuf(23), bBuf(22))
    End If

    End If

    If bBuf(0) = 71 And bBuf(1) = 73 And bBuf(2) = 70 Then
    ' dit is een gif file

    m_ImageType = itGIF

    ' de breedte
    m_Width = Mult(bBuf(6), bBuf(7))

    ' de hoogte
    m_Height = Mult(bBuf(8), bBuf(9))

    ' bit diepte
    m_Depth = (bBuf(10) And 7) + 1
    End If

    If bBuf(0) = 66 And bBuf(1) = 77 Then
    ' dit is een bmp file

    m_ImageType = itBMP

    ' de breedte
    m_Width = Mult(bBuf(18), bBuf(19))

    ' de hoogte
    m_Height = Mult(bBuf(22), bBuf(23))

    ' bit diepte
    m_Depth = bBuf(28)
    End If

    If m_ImageType = itUNKNOWN Then
    'als het niet een van de bovenstaande is
    'dan controleren we of het mischien een jpeg is
    Dim lPos As Long

    Do
    ' loop zoekend naar byte volgorde FF,D8,FF
    ' die het begin van een jpeg aangeeft
    ' lPos returns links van de positie van het startpunt van de jpeg
    If (bBuf(lPos) = &HFF And bBuf(lPos + 1) = &HD8 _
    And bBuf(lPos + 2) = &HFF) _
    Or (lPos >= BUFFERSIZE - 10) Then Exit Do

    ' pointer verplaatsen
    lPos = lPos + 1

    ' en doorgaan
    Loop

    lPos = lPos + 2
    If lPos >= BUFFERSIZE - 10 Then Exit Sub


    Do
    'zoeken naar FF,C0 dit is het blok met de informatie
    Do
    ' zoeken naar het begin van de markering
    If bBuf(lPos) = &HFF And bBuf(lPos + 1) _
    <> &HFF Then Exit Do
    lPos = lPos + 1
    If lPos >= BUFFERSIZE - 10 Then Exit Sub
    Loop

    ' pointer verplaatsen
    lPos = lPos + 1

    Select Case bBuf(lPos)
    Case &HC0 To &HC3, &HC5 To &HC7, &HC9 To &HCB, _
    &HCD To &HCF
    ' we vinden het juiste blok
    Exit Do
    End Select

    'anders doorzoeken
    lPos = lPos + Mult(bBuf(lPos + 2), bBuf(lPos + 1))

    ' controleer of we het einde van de buffer bereiken
    If lPos >= BUFFERSIZE - 10 Then Exit Sub

    Loop

    ' als we op dit punt zijn aangekomen dan is het een Jpeg
    ' en zijn we klaar om de informatie te pakken

    m_ImageType = itJPEG

    ' de hoogte
    m_Height = Mult(bBuf(lPos + 5), bBuf(lPos + 4))

    'de breedte
    m_Width = Mult(bBuf(lPos + 7), bBuf(lPos + 6))

    'de kleurdiepte
    m_Depth = bBuf(lPos + 8) * 8

    End If
    Err.Clear
    End Sub
    Private Function Mult(lsb As Byte, msb As Byte) As Long
    Mult = lsb + (msb * CLng(256))
    End Function

  3. #3
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:BMP Information Program Size

    [Originally posted by Miner=(]

    Thanks but... not what i was looking for

    I want to get the filesize of the image like 1024 bytes but the image it self look at this dummy file.
    I was the Data after the image inside the same file extracted in 1 textbox and image in the a picturebox or just a module would help
    http://runescapesig.clawz.com/dummy.file

    please know that dummy.file (isn't just a image) it has Data on the bottom of it

    Lol dont mind this server clawz it removes changes the file from .file to .bmp but you can still see it in hex

    thanks ~~

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center