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. Visual Basic
  4. converting 24bit color depth image to 1bpp image

converting 24bit color depth image to 1bpp image

Scheduled Pinned Locked Moved Visual Basic
graphicsquestion
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.
  • P Offline
    P Offline
    pnpfriend
    wrote on last edited by
    #1

    Hi, I am trying to convert the 24 bit image to 1 bit image. How can I convert it. I had tried the following code and obviously it didn't work. Thank You. Public Function ConvertTo1bpp(ByVal img As Bitmap) As Bitmap Dim rc As New Rectangle(0, 0, img.Width, img.Height) Dim bmpS As New Bitmap(img.Width, img.Height, PixelFormat.Format1bppIndexed) bmpS.SetResolution(img.HorizontalResolution, img.VerticalResolution) Dim bmpDataSet As BitmapData = bmpS.LockBits(rc, ImageLockMode.ReadWrite, PixelFormat.Format1bppIndexed) Dim bmpDataSource As BitmapData = img.LockBits(rc, ImageLockMode.ReadOnly, img.PixelFormat) bmpDataSource.PixelFormat = PixelFormat.Format1bppIndexed img.UnlockBits(bmpDataSource) Return img End Function

    D C 2 Replies Last reply
    0
    • P pnpfriend

      Hi, I am trying to convert the 24 bit image to 1 bit image. How can I convert it. I had tried the following code and obviously it didn't work. Thank You. Public Function ConvertTo1bpp(ByVal img As Bitmap) As Bitmap Dim rc As New Rectangle(0, 0, img.Width, img.Height) Dim bmpS As New Bitmap(img.Width, img.Height, PixelFormat.Format1bppIndexed) bmpS.SetResolution(img.HorizontalResolution, img.VerticalResolution) Dim bmpDataSet As BitmapData = bmpS.LockBits(rc, ImageLockMode.ReadWrite, PixelFormat.Format1bppIndexed) Dim bmpDataSource As BitmapData = img.LockBits(rc, ImageLockMode.ReadOnly, img.PixelFormat) bmpDataSource.PixelFormat = PixelFormat.Format1bppIndexed img.UnlockBits(bmpDataSource) Return img End Function

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      This isn't going to work because how does the code know which pixels to turn on and which to turn off?? 1bpp only leaves white and black as your colors, so you need to come up with a cut off point in the original image to make the conversion mean anything. In other words, if the brightness of a color is below a certain threashold, the target pixel should be black, otherwise it's white. This code will not do that for you. 3 seconds worth of Google came up with this[^] C# source to do the conversion your talking about.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      P 1 Reply Last reply
      0
      • P pnpfriend

        Hi, I am trying to convert the 24 bit image to 1 bit image. How can I convert it. I had tried the following code and obviously it didn't work. Thank You. Public Function ConvertTo1bpp(ByVal img As Bitmap) As Bitmap Dim rc As New Rectangle(0, 0, img.Width, img.Height) Dim bmpS As New Bitmap(img.Width, img.Height, PixelFormat.Format1bppIndexed) bmpS.SetResolution(img.HorizontalResolution, img.VerticalResolution) Dim bmpDataSet As BitmapData = bmpS.LockBits(rc, ImageLockMode.ReadWrite, PixelFormat.Format1bppIndexed) Dim bmpDataSource As BitmapData = img.LockBits(rc, ImageLockMode.ReadOnly, img.PixelFormat) bmpDataSource.PixelFormat = PixelFormat.Format1bppIndexed img.UnlockBits(bmpDataSource) Return img End Function

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        You can actually create a new 1bit bitmap and draw your 24bit image onto it, if you want to see what sort of conversion you get by default. However, Dave has given you a link if you wanted to control the threshold yourself.

        Christian Graus Driven to the arms of OSX by Vista.

        1 Reply Last reply
        0
        • D Dave Kreskowiak

          This isn't going to work because how does the code know which pixels to turn on and which to turn off?? 1bpp only leaves white and black as your colors, so you need to come up with a cut off point in the original image to make the conversion mean anything. In other words, if the brightness of a color is below a certain threashold, the target pixel should be black, otherwise it's white. This code will not do that for you. 3 seconds worth of Google came up with this[^] C# source to do the conversion your talking about.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          P Offline
          P Offline
          pnpfriend
          wrote on last edited by
          #4

          Thank You Dave. I had looked at that link and already using it. There is a problem so I had to post this message here. I should be more specified on my question. Here is what i want.. I have color Jpg image file and I converted it to black and white tiff image using colorMatrix. Everything came out good but the tiff image is in 24 bit color depth. I need it to 1 bit color depth and should not change the look of tiff image. I also found out if the tiff image is in floyd-steinberg and it can have grayscal with 1pbb. But I just dont 'know how to do it. Here what i did. 1) convert the jpg to GrayScale() using colorMatrix 2) then use the result image which is black and white with 24 bpp and convert it to 1bpp using the example on this link http://www.wischik.com/lu/programmer/1bpp.html[^] but the image turn all black and white .. no more shadow.. depth like I have before.

          C D 2 Replies Last reply
          0
          • P pnpfriend

            Thank You Dave. I had looked at that link and already using it. There is a problem so I had to post this message here. I should be more specified on my question. Here is what i want.. I have color Jpg image file and I converted it to black and white tiff image using colorMatrix. Everything came out good but the tiff image is in 24 bit color depth. I need it to 1 bit color depth and should not change the look of tiff image. I also found out if the tiff image is in floyd-steinberg and it can have grayscal with 1pbb. But I just dont 'know how to do it. Here what i did. 1) convert the jpg to GrayScale() using colorMatrix 2) then use the result image which is black and white with 24 bpp and convert it to 1bpp using the example on this link http://www.wischik.com/lu/programmer/1bpp.html[^] but the image turn all black and white .. no more shadow.. depth like I have before.

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            pnpfriend wrote:

            I need it to 1 bit color depth and should not change the look of tiff image. I also found out if the tiff image is in floyd-steinberg and it can have grayscal with 1pbb.

            No, that is not true. A 1 bpp image has two colors, black and white. This is greyscale only in that those two colors are the two extremes of the greyscale range. A greyscale image is 8bpp.

            pnpfriend wrote:

            but the image turn all black and white .. no more shadow.. depth like I have before.

            That is exactly what converting to 1bpp will do. EVERY time.

            Christian Graus Driven to the arms of OSX by Vista.

            1 Reply Last reply
            0
            • P pnpfriend

              Thank You Dave. I had looked at that link and already using it. There is a problem so I had to post this message here. I should be more specified on my question. Here is what i want.. I have color Jpg image file and I converted it to black and white tiff image using colorMatrix. Everything came out good but the tiff image is in 24 bit color depth. I need it to 1 bit color depth and should not change the look of tiff image. I also found out if the tiff image is in floyd-steinberg and it can have grayscal with 1pbb. But I just dont 'know how to do it. Here what i did. 1) convert the jpg to GrayScale() using colorMatrix 2) then use the result image which is black and white with 24 bpp and convert it to 1bpp using the example on this link http://www.wischik.com/lu/programmer/1bpp.html[^] but the image turn all black and white .. no more shadow.. depth like I have before.

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              pnpfriend wrote:

              no more shadow.. depth like I have before.

              Unless you use some kind of dithering algorithm to get the effect you want, you can't get "shadows" in a single bpp image.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008

              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