none
Save bitmap as 8 bit not 32 bit

    Question

  • I've created a new bitmap object and am shading some pixels inside it black using the setpixel function.

    At the end I do: myBlankBitmap.Save("D:\3Didea_out.bmp")

    Great. Except the bitmap that is saved is 32bit and won't open properly. I want it to be 8 bit. I can't find any options to change the bitdepth. I'm really confused.

    Any ideas how to save as 8 bit? Thanks

    Sunday, May 16, 2010 3:06 PM

All replies

  • Thanks - I tried that already but the gif pixel depth is still 32 bit = no good.

     

    Sunday, May 16, 2010 3:29 PM
  • I found this by doing a very quick search of the internet:

    http://bytes.com/topic/c-sharp/answers/567407-convert-image-8-bit-grayscale

    Look at post #4 in the above link for the answer.  The code is C#, but it can be converted to VB.NET at the following site:

    http://www.developerfusion.com/tools/convert/csharp-to-vb

     


    Doug

    SEARCH ... then ask
    Sunday, May 16, 2010 4:42 PM
  • Thanks - I tried that already but the gif pixel depth is still 32 bit = no good.

    No!  Gifs are 8 bit by definition.  Are you just changing the extension?  You have to specify the encoder for all but the default png.  Do you want to specify the palette?
    Sunday, May 16, 2010 6:31 PM
  • Thank you for your replies. I should have pointed out I spent quite a bit of time searching before posting here. Doug's solution is incredibly long winded and I don't understand how to implement it.

    I was just hoping there'd be an easy option to creat an 8 bit bmp. There is, but when I specify 8bit VB won't let me use the setpixel function because the 8bit bmp doesn't have a palette. I can't find the creat palette function.

    In a nutshell this is beyond me. Turns out I can open the 32 bit bmp in Paint and save them as 8bit. This is rather easier than trying to rewrite a simple function which I'm surprised VB makes so hard for novices like me.

    Sunday, May 16, 2010 8:38 PM
  • Hi,

    if you create your bitmap like in the codeline below, you should get a 8bit bitmap:


    'Visual Basic 2008 - .net 3.5 - Any CPU
    Dim MyBmp As New Bitmap(50, 50, Imaging.PixelFormat.Format8bppIndexed)

     


    Hannes

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    Sunday, May 16, 2010 8:52 PM
  • Correct. But then I can't 'paint' that bmp because I get an error using the setpixel command. It's a lose lose situation
    Sunday, May 16, 2010 9:07 PM
  • Thank you for your replies. I should have pointed out I spent quite a bit of time searching before posting here. Doug's solution is incredibly long winded and I don't understand how to implement it.

    I was just hoping there'd be an easy option to creat an 8 bit bmp. There is, but when I specify 8bit VB won't let me use the setpixel function because the 8bit bmp doesn't have a palette. I can't find the creat palette function.

    In a nutshell this is beyond me. Turns out I can open the 32 bit bmp in Paint and save them as 8bit. This is rather easier than trying to rewrite a simple function which I'm surprised VB makes so hard for novices like me.


    Using a program should be easier than writing the program.  Writing the program requires amassing a body of knowledge and presenting tools to use it in a simplified manner.  Graphics to the user seems very simple.  Graphics to the novice programmer seems very complex. 
    Sunday, May 16, 2010 9:14 PM
  • I would hate for Microsoft to avoid making graphics programming easier or more intuitive simply because some users prefer that status quo. After all, this is VB don't forget.....couldn't they make it less confusing to save an 8 bit bmp? Should I really have to jump through a ton of hoops to do something so simple? I don't think I should.
    Sunday, May 16, 2010 10:18 PM
  • Can I just add that I'm writing this program for myself. It's not for anyone else. So I'd rather it was just easy for me to write and easy for me to use. Or even hard for me to use. I don't care.

    I just can't understand how anyone can justify procedures that for whatever reason are harder than they need to be. That is after all the heart of bureaucracy, one of life's worst features.

    Sunday, May 16, 2010 10:27 PM