如何使用GDI +使用16bppGrayScale绘制位图? [英] How can I draw a bitmap with 16bppGrayScale using GDI+?

查看:431
本文介绍了如何使用GDI +使用16bppGrayScale绘制位图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用Graphics.DrawImage()绘制位图时,发生了错误.我必须先将16bppGrayScale位图转换为8bppIndexed位图,然后再将其转换为24bppRgb位图,现在GDI +可以正确绘制了.想问一问是否有办法直接使用GDI +绘制16bppGrayScale位图.谢谢.

When I draw the bitmap using Graphics.DrawImage(),it occurre an error.I had to convert the 16bppGrayScale bitmap to 8bppIndexed bitmap first,then convert it to 24bppRgb bitmap,now the GDI+ can draw it correctly.So,I would like to ask whether there is an way to draw 16bppGrayScale bitmap directly using GDI+.Thanks.

推荐答案

没有办法直接利用GDI +绘制16bppGrayScale位图. br/> 因为您无法从Format16bppGrayScale图像获取Graphics对象.
即:

位图位图=新位图(256、256,PixelFormat.Format16bppGrayScale);
图形g = Graphics.FromImage((Image)bitmap);

这将引发错误.

您做得正确,但代价是降低了图像的辐射分辨率.
我的意思是Format16bppGrayscale的动态范围(像素值范围)应为0-65535(但是,您正在将该值范围转换为0-255:Format8bppIndexed).

实际上,在.NET中,它仅为0-8192.此范围应在0-65535之间(.NET的Format16bppGrayscale图像格式有此问题).

如果您尝试以Format16bppGrayscale绘制图像而不会丢失辐射分辨率,请从Format16bppGrayscale图像创建一个Format48bppRgb图像,然后使用GDI +绘制它.
There is no a way to draw 16bppGrayScale bitmap directly using GDI+.
Because you can not get Graphics object from Format16bppGrayScale image.
Namely:

Bitmap bitmap = new Bitmap(256, 256, PixelFormat.Format16bppGrayScale);
Graphics g = Graphics.FromImage((Image)bitmap);

This will throw error.

You are doing correct in expensive of degrading radiometric resolution of the image.
My mean is the dynamic range (pixel value range) of the Format16bppGrayscale is should be 0-65535 (However, you are converting this value range to 0-255: Format8bppIndexed).

Actually, in .NET it is only 0-8192. This should be in the range of 0-65535(This is something wrong in .NET''s Format16bppGrayscale image format).

If you are trying to draw the image in Format16bppGrayscale without radiometric resolution lost, please create a Format48bppRgb image from your Format16bppGrayscale image, then, draw it by using GDI+.


hi,

但是位图图像创建代码,您必须需要在任何控件(例如面板,窗体等)的_paint()方法中进行编写,这是代码

图片bmp =新的位图(200,40,System.Drawing.Imaging.PixelFormat.Format16bppArgb1555);

使用(Graphics g = Graphics.FromImage(bmp))
{
g.FillRectangle(Brushes.White,0,0,Width,Height);

panel1_Paint(null,新的PaintEventArgs(g,this.ClientRectangle));

bmp.Save(file,System.Drawing.Imaging.ImageFormat.Jpeg);
}


but bitmap image creation code you must need to Write in _paint() method of the any control like panel,form etc and here is the code

Image bmp = new Bitmap(200, 40, System.Drawing.Imaging.PixelFormat.Format16bppArgb1555);

using (Graphics g = Graphics.FromImage(bmp))
{
g.FillRectangle(Brushes.White, 0, 0, Width, Height);

panel1_Paint(null, new PaintEventArgs(g, this.ClientRectangle));

bmp.Save(file, System.Drawing.Imaging.ImageFormat.Jpeg);
}


这篇关于如何使用GDI +使用16bppGrayScale绘制位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆