本文介绍了将8位彩色bmp图像转换为8位灰度bmp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的位图对象
Bitmap b = new Bitmap(columns, rows, PixelFormat.Format8bppIndexed);
BitmapData bmd = b.LockBits(new Rectangle(0, 0, columns, rows), ImageLockMode.ReadWrite, b.PixelFormat);
如何将其转换为8位灰度位图?
How do i convert this into a 8 bit grayscale bitmap ?
推荐答案
您可以将调色板更改为灰度调色板
hi you could change the color palette to a grayscale one
尽管下面的代码在Vb.net中.您可以轻松地将其转换为C#
although the following code is in Vb.net. You could easily convert it to C#
Private Function GetGrayScalePalette() As ColorPalette
Dim bmp As Bitmap = New Bitmap(1, 1, Imaging.PixelFormat.Format8bppIndexed)
Dim monoPalette As ColorPalette = bmp.Palette
Dim entries() As Color = monoPalette.Entries
Dim i As Integer
For i = 0 To 256 - 1 Step i + 1
entries(i) = Color.FromArgb(i, i, i)
Next
Return monoPalette
End Function
原始来源-> http://social.msdn.microsoft.com/Forums/en-us/vblanguage/thread/500f7827-06cf-4646-a4a1-e075c16bbb38
这篇关于将8位彩色bmp图像转换为8位灰度bmp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!