CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Posts
    19

    Image size in the Picture Box?

    How do I get the size of the picture or image that I have loaded onto the Picture Box, in bytes. Could you provide me with the functions or source code in VB?

    Thank you.
    dev.


  2. #2
    Join Date
    May 2001
    Location
    New Jersey, USA
    Posts
    47

    Re: Image size in the Picture Box?

    Try this extra-cheesy code to get Bitmap size:
    Remember to repalce "Picture.BMP" with a valid file name


    ' from MSDN
    private Type BITMAPINFOHEADER '40 bytes
    biSize as Long ' not the image size
    biWidth as Long
    biHeight as Long
    biPlanes as Integer
    biBitCount as Integer ' 2 ^ InfoHeader.biBitCount = Bits per Pixel
    biCompression as Long ' 0=none, 1=RLE8, 2=RLE4, 3=BitFields
    biSizeImage as Long ' # of bytes for image, not the file size , not all

    'graphics programs fill this in properly is 1K = 1000 OR = 1024
    ' try this: it should be close
    ' (InfoHeader.biBitCount / 8) * InfoHeader.biWidth * InfoHeader.biHeight
    biXPelsPerMeter as Long
    biYPelsPerMeter as Long
    biClrUsed as Long ' colors used in this image
    biClrImportant as Long ' colors important to this image
    End Type

    private Type BITMAPFILEHEADER
    bfType as Integer
    bfSize as Long
    bfReserved1 as Integer
    bfReserved2 as Integer
    bfOhFileBits as Long
    End Type

    ' replace "Picture.BMP" with common dialog or some valid name

    aFile = FreeFile
    Open "Picture.BMP" for binary Access Read as #aFile
    get #aFile, , FileHeader
    get #aFile, , InfoHeader
    Close #aFile

    MsgBox "This image is :" & vbCrLf & _
    InfoHeader.biHeight & " Pixels High" & vbCrLf & _
    InfoHeader.biWidth & " Pixels Wide" & vbCrLf & _
    InfoHeader.biSizeImage & " Bytes (header)" & vbCrLf & _
    (InfoHeader.biBitCount / 8) * InfoHeader.biWidth * InfoHeader.biHeight & _
    " Bytes (calculated)"






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

Featured