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. Lockbits and 8-bit grayscale images

Lockbits and 8-bit grayscale images

Scheduled Pinned Locked Moved C#
question
6 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.
  • G Offline
    G Offline
    gigahertz205
    wrote on last edited by
    #1

    I have to pass pixelformat as a parameter when performing lockbits. But for grayscale images, there is only "Format16bppGrayscale." Does this format work with 8 bit grayscale images? If not, how do i use lockbits with 8bit grayscale images?

    G 1 Reply Last reply
    0
    • G gigahertz205

      I have to pass pixelformat as a parameter when performing lockbits. But for grayscale images, there is only "Format16bppGrayscale." Does this format work with 8 bit grayscale images? If not, how do i use lockbits with 8bit grayscale images?

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      No. Use PixelFormat.Format8bppIndexed.

      Despite everything, the person most likely to be fooling you next is yourself.

      G 1 Reply Last reply
      0
      • G Guffa

        No. Use PixelFormat.Format8bppIndexed.

        Despite everything, the person most likely to be fooling you next is yourself.

        G Offline
        G Offline
        gigahertz205
        wrote on last edited by
        #3

        if its 8-bit then shouldn't the values range from 0-255? I get black pixel as 0 and white as 169. Is this what its supposed to be?

        L 1 Reply Last reply
        0
        • G gigahertz205

          if its 8-bit then shouldn't the values range from 0-255? I get black pixel as 0 and white as 169. Is this what its supposed to be?

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi, 169 is two thirds of 255, as if you started off with an RGB image and either one component was absent, or something else went terribly wrong in the color-to-grayscale conversion. Or did you have an ARGB image (A=alpha=opacity) and take the wrong 3 out of 4 bytes? :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          Voting for dummies? No thanks. X|


          G 1 Reply Last reply
          0
          • L Luc Pattyn

            Hi, 169 is two thirds of 255, as if you started off with an RGB image and either one component was absent, or something else went terribly wrong in the color-to-grayscale conversion. Or did you have an ARGB image (A=alpha=opacity) and take the wrong 3 out of 4 bytes? :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            Voting for dummies? No thanks. X|


            G Offline
            G Offline
            gigahertz205
            wrote on last edited by
            #5

            Hmm it must be the website that i downloaded the image from. Im using the Lena picture in grayscale, which i previously downloaded. I downloaded the color version of lena and converted into grayscale using photoshop. Pixels return intensities properly now. Thank you.

            G 1 Reply Last reply
            0
            • G gigahertz205

              Hmm it must be the website that i downloaded the image from. Im using the Lena picture in grayscale, which i previously downloaded. I downloaded the color version of lena and converted into grayscale using photoshop. Pixels return intensities properly now. Thank you.

              G Offline
              G Offline
              Guffa
              wrote on last edited by
              #6

              Are you sure that it actually is a grayscale image, and not an indexed image that had a palette of 170 grayscale colors? I found one Lena picture in grascale, that is a GIF image with a 215 color palette.

              Despite everything, the person most likely to be fooling you next is yourself.

              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