0

I'm creating a Bitmap in C# from an Image object.

The Bitmap I get is 32bpp, how can I transform that to 16bpp?

Bitmap image_bmp;
System.Drawing.Image tmp = (System.Drawing.Image)img.RenderImage(0); //RenderImage creates an object of tyoe System.Drawing.Image
image_bmp = new Bitmap(tmp);
drew_w
  • 10,320
  • 4
  • 28
  • 49
Matimont
  • 739
  • 3
  • 14
  • 33
  • 16bpp ...grayscale? color? You'll need to be a bit more specific on what format you want! : ) – drew_w Jun 20 '14 at 19:50

1 Answers1

1

If you run a quick search on google you can find a number of excellent color to grayscale formulas. Take the following from wikipedia as an example:

Y' =  0.2126 R' + 0.7152 G' + 0.0722 B'

With this in mind the general process in .NET is going to be:

  • Create a new image of the correct dimensions with 16bpp grayscale
  • Use "LockBits" on the original image and the new image and loop over each pixel
  • Unlock both images, then save the new image to a file

Rather than going into these steps further I found a few other questions from stack and around the web that really delve into the details more. See:

Best of luck!

NOTE - I'm assuming your using GDI+. The steps are is similar for Windows Imaging Component (WIC) but the classes and syntax is radically different.

Community
  • 1
  • 1
drew_w
  • 10,320
  • 4
  • 28
  • 49