none
conversion of 8-bit bitmap to 24-bit bitmap RRS feed

  • Question

  • hello.

     

    i am currently on doing some C# programming project. and i am having trouble in changing the format of my image that i capture from my framegrabber, which is 8-bit size to 24-bit size...

    i was advice to make 2 other layers on the original 8-bit bitmap image that i have captured from the framgrabber.

    how do i go about with this?

    include reference website or codes if possible.

    pls help.

    Thursday, June 14, 2007 5:14 AM

Answers

  • Hi,

    And another better compliment would be as follows: 

    Code Snippet

            Bitmap bm8bit = new Bitmap("E:\\8bit.bmp");

            Bitmap bm24bit = new Bitmap(bm8bit.Width, bm8bit.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            Graphics g = Graphics.FromImage(bm24bit);

            g.DrawImage(bm8bit, 0, 0, bm8bit.Width, bm8bit.Height);

            bm24bit.Save(@"C:\bit24.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

            g.Dispose();

            bm8bit.Dispose();

            bm24bit.Dispose();

     

    Thanks

    Friday, June 22, 2007 2:33 AM
  • Hi, diditel

    To convert 8-bit to 24-bit image, one way is to draw another bitmap based on original bitmap's pixel color:

    Code Snippet
                Bitmap image = new Bitmap(@"C:\bit8.bmp");
                Bitmap bitmap = new Bitmap(image.Width, image.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                for (int i = 0; i < image.Width; i++)
                {
                    for (int j = 0; j < image.Height; j++)
                    {
                        Color temp = image.GetPixel(i, j);
                        bitmap.SetPixel(i, j, temp);
                    }
                }
                bitmap.Save(@"C:\bit24.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

     

    Thanks

    Tuesday, June 19, 2007 7:37 AM

All replies

  • Hi, diditel

    To convert 8-bit to 24-bit image, one way is to draw another bitmap based on original bitmap's pixel color:

    Code Snippet
                Bitmap image = new Bitmap(@"C:\bit8.bmp");
                Bitmap bitmap = new Bitmap(image.Width, image.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                for (int i = 0; i < image.Width; i++)
                {
                    for (int j = 0; j < image.Height; j++)
                    {
                        Color temp = image.GetPixel(i, j);
                        bitmap.SetPixel(i, j, temp);
                    }
                }
                bitmap.Save(@"C:\bit24.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

     

    Thanks

    Tuesday, June 19, 2007 7:37 AM
  • Hi,

    And another better compliment would be as follows: 

    Code Snippet

            Bitmap bm8bit = new Bitmap("E:\\8bit.bmp");

            Bitmap bm24bit = new Bitmap(bm8bit.Width, bm8bit.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            Graphics g = Graphics.FromImage(bm24bit);

            g.DrawImage(bm8bit, 0, 0, bm8bit.Width, bm8bit.Height);

            bm24bit.Save(@"C:\bit24.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

            g.Dispose();

            bm8bit.Dispose();

            bm24bit.Dispose();

     

    Thanks

    Friday, June 22, 2007 2:33 AM