Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How can i know what is the bitmap color size of each pixel ?

How can i know what is the bitmap color size of each pixel ?

Scheduled Pinned Locked Moved C#
questiontutorialgraphics
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I have some bitmap. I know that the bitmap format is PixelFormat.FormatXXXXXXbppRgb ==> but i want dynamically to calculate the size of each pixel. For example ==> if the bitmap pixel format is Format24bppRgb i want to calculate that the R/G/B range is between 0 to 255. So, i don't know how to get the information that in case of Format24bppRgb the R/G/B bit size is 3. or that in the format is Format32bppRgb that the R/G/B bit size is 4. P.S: i don't want to use the code BitmapData bmDateFrame = bitmap.LockBits(....) Int32 picPixelBit = bmDateFrame.Stride / bitmap.Width;

    D _ 2 Replies Last reply
    0
    • L Lost User

      I have some bitmap. I know that the bitmap format is PixelFormat.FormatXXXXXXbppRgb ==> but i want dynamically to calculate the size of each pixel. For example ==> if the bitmap pixel format is Format24bppRgb i want to calculate that the R/G/B range is between 0 to 255. So, i don't know how to get the information that in case of Format24bppRgb the R/G/B bit size is 3. or that in the format is Format32bppRgb that the R/G/B bit size is 4. P.S: i don't want to use the code BitmapData bmDateFrame = bitmap.LockBits(....) Int32 picPixelBit = bmDateFrame.Stride / bitmap.Width;

      D Offline
      D Offline
      David Ewen
      wrote on last edited by
      #2

      There doesn't appear to be an easy way to do this from what I can tell. but looking at the PixelFormat Enumeration[^] it is only going to be 8 or 16 bits per pixel so a small switch statement should do the job. The bigger question is why do you need to know this? There is most likely a better way as I have never needed to know this information.

      1 Reply Last reply
      0
      • L Lost User

        I have some bitmap. I know that the bitmap format is PixelFormat.FormatXXXXXXbppRgb ==> but i want dynamically to calculate the size of each pixel. For example ==> if the bitmap pixel format is Format24bppRgb i want to calculate that the R/G/B range is between 0 to 255. So, i don't know how to get the information that in case of Format24bppRgb the R/G/B bit size is 3. or that in the format is Format32bppRgb that the R/G/B bit size is 4. P.S: i don't want to use the code BitmapData bmDateFrame = bitmap.LockBits(....) Int32 picPixelBit = bmDateFrame.Stride / bitmap.Width;

        _ Offline
        _ Offline
        _Erik_
        wrote on last edited by
        #3

        The size of each pixel depends only on the pixel format. You can see here[^] the lenght for each pixel format and how many bits are used for each A/R/G/B component.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups