0

Im working on app for my educational purposes.

I want to make any image (jpg, png) from 24/32bpp to 8bpp, because i only want values from 0 to 255 in one scale (in this situation, gryascale) and i dont need to have RGB or RGBA color space.

I found a solution for it, can i use Graphics.DrawImage for making a copy of my input image, but with cutting not needed channels? Of course, after binarize the image.

//binarization first

static public Bitmap CreateNonIndexedImage(Bitmap bitmap)
    {
        Bitmap newBmp = new Bitmap(bitmap.Width, bitmap.Height, PixelFormat.Format32bppArgb); // i want to change pixel format here

        using (Graphics graphics = Graphics.FromImage(newBmp))
        {
            graphics.DrawImage(bitmap, 0, 0); //if it make an exact copy of input bitmap?
        }

        return newBmp;
    }

Thanks for any advices

  • 1
    https://stackoverflow.com/questions/21856184/the-best-way-to-reduce-quantity-of-colors-in-bitmap-palette?rq=1 – xxbbcc Aug 16 '18 at 17:40
  • 1
    The link points to a palette optimzer. Hardly what Op wants. – TaW Aug 16 '18 at 17:42
  • 1
    You can create an 8bpp bitmap but a) it will be indexed (so you need to add a palette) and b) you can't do GDI drawing onto it. You will need to set the bytes yourself, after converting the original to grayscale, maybe with a color matrix. – TaW Aug 16 '18 at 17:44

0 Answers0