使 24 位彩色位图以正常亮度级别保存
这是我的位图创建代码
public static Bitmap Plot24(ref byte[] bufferArray, int lengthOfBufferArray, String fileName)
{
int position = 0;
int rows = (int)Math.Ceiling((double)lengthOfBufferArray / (3*columns) );
Bitmap b = new Bitmap(columns , rows, PixelFormat.Format24bppRgb);
BitmapData bmd = b.LockBits(new Rectangle(0, 0, columns , rows), ImageLockMode.ReadWrite, b.PixelFormat);
unsafe
{
for (int j = 0; j < rows; j++)
{
byte* row = (byte*)bmd.Scan0 + ((j * bmd.Stride) );
for (int i = 0; i < columns*3; i+=3)
{
if (position < lengthOfBufferArray)
{
try
{
row[i+2] = bufferArray[position];
position++;
if (position < lengthOfBufferArray)
{
row[i+1] = bufferArray[position];
position++;
}
else
{
break;
}
if (position < lengthOfBufferArray)
{
row[i] = bufferArray[position];
position++;
}
else
{
break;
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
b.UnlockBits(bmd);
return b;
}
}
这就是我保存返回的位图的方式
b.Save(outputFilename, ImageFormat.Bmp);
当我在 bufferArray 中拥有所有 FF 十六进制时,白色像素仍然不是那么白色。
当我在 bufferArray 中有随机值时,其他颜色看起来也像是被冲走了。
我怎样才能让它以正常亮度级别保存?
This is my bitmap creation code
public static Bitmap Plot24(ref byte[] bufferArray, int lengthOfBufferArray, String fileName)
{
int position = 0;
int rows = (int)Math.Ceiling((double)lengthOfBufferArray / (3*columns) );
Bitmap b = new Bitmap(columns , rows, PixelFormat.Format24bppRgb);
BitmapData bmd = b.LockBits(new Rectangle(0, 0, columns , rows), ImageLockMode.ReadWrite, b.PixelFormat);
unsafe
{
for (int j = 0; j < rows; j++)
{
byte* row = (byte*)bmd.Scan0 + ((j * bmd.Stride) );
for (int i = 0; i < columns*3; i+=3)
{
if (position < lengthOfBufferArray)
{
try
{
row[i+2] = bufferArray[position];
position++;
if (position < lengthOfBufferArray)
{
row[i+1] = bufferArray[position];
position++;
}
else
{
break;
}
if (position < lengthOfBufferArray)
{
row[i] = bufferArray[position];
position++;
}
else
{
break;
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
b.UnlockBits(bmd);
return b;
}
}
And this is how i save the returned bitmap
b.Save(outputFilename, ImageFormat.Bmp);
When i have all FF hexadecimals in the bufferArray still the white pixels are not that white.
And when i have random values in the bufferArray other colors also look like they are washed away.
How can i make it save in the normal brightness level ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我测试了你的示例代码,它工作得很好。我在我的底部摘录了您的示例,并对方法参数进行了一些细微的修改。
您能否在问题中提供一个如何使用 Plot24 方法的示例?也许问题就出在这里。
I tested your sample code and it worked just fine. I have an excerpt of you sample at the bottom of mine with some slight modification to the method parameters.
Could you supply in your question a sample of how you use your Plot24 method? Maybe the problem lies there.