Results 1 to 4 of 4

Thread: Checking for 24 bit or 32 bit Images

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    76

    Checking for 24 bit or 32 bit Images

    I have not done any coding for a while and am still using VB Express 2013 ...

    I have a whole set of routines I have cobbled together over the years which read an image (eg a JPG) from disc and then convert it into a Byte array. I can then do stuff to the array and then stick it into a picturebox and then back onto the disc.

    This all works fine BUT I need to be able to tell if an Image is 24 bit or 32 bit when I load it. Is there a way of doing this - I guess I could read the header but that sounds like hard work ...

    Thank you all in anticipation!

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,971

    Re: Checking for 24 bit or 32 bit Images


  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    76

    Re: Checking for 24 bit or 32 bit Images

    Quote Originally Posted by .paul. View Post
    That does it in two lines after the usual going round the houses

    Dim myJpgImage As Image = Image.FromFile("C:\test.jpg")
    MsgBox(myJpgImage.PixelFormat.ToString)

    The message reads: Format24bppRgb

    Many thanks!

    PS You can do it ONE line from a PictureBox (duh)

    strTemp = picBox.Image.PixelFormat.ToString

    So what it boils down to is that "PixelFormat" is an Image property and you can access it!
    Last edited by wavering; Dec 17th, 2020 at 05:38 AM.

  4. #4
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,163

    Re: Checking for 24 bit or 32 bit Images

    If you just want to check the pixel size, you can do it in one line:
    Code:
    Dim bitsPerPixel As Integer = Bitmap.GetPixelFormatSize(bitmap name.PixelFormat)
    Result: 24 or 32 (you won't often get 8, 16 etc.).

    BB

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