How to create Bitmap from System.Window.media.PixelFormats.Gray16
I am successfully drawing images from their raw pixel data (8bit images only). here is the code to accomplish the same.
PixelFormat format = PixelFormat.Format8bppIndexed;
Bitmap bmp = new Bitmap(Img_Width, Img_Height, format);
Rectangle rect = new Rectangle(0, 0, Img_Width, Img_Height);
BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, format);
Marshal.Copy(rawPixel, 0, bmpData.Scan0, rawPixel.Length);
bmp.UnlockBits(bmpData);
Now, as you all know, PixelFormat.format16bppGrayscale is not supported by C # 2.0 GDI +. I googled and got 3.0 / 3.5 Framework support. So I installed both. The class that is supporting is System.windows.media.PixelFormats. PixelFormats.Gray16
Now my problem is how to create a bitmap and get the image to display by passing this parameter.
I have a BitmapSource class, but I am very new to C # 3.0.
Please help me.
0
a source to share
2 answers
Try the following:
private static Bitmap changePixelFormat(Bitmap input, PixelFormat format)
{
Bitmap retval=new Bitmap(input.Width, input.Height, format);
retval.SetResolution(input.HorizontalResolution, input.VerticalResolution);
Graphics g = Graphics.FromImage(retval);
g.DrawImage(input, 0, 0);
g.Dispose();
return retval;
}
0
a source to share
Check out Grayscale Filters at AForge.net . You can find the source here .
EDIT:
As a side note to this source I linked to, it uses the "old" version of AForge.NET, but the concepts are the same.
0
a source to share