【发布时间】:2017-05-10 11:30:45
【问题描述】:
我有一个带有PixelFormat 的Format32bppRgb 的System.Drawing.Bitmap。
我想把这张图片转换成8bit的位图。
以下是将32位图像转换为8位灰度图像的代码:
public static Bitmap ToGrayscale(Bitmap bmp)
{
int rgb;
System.Drawing.Color c;
for (int y = 0; y < bmp.Height; y++)
for (int x = 0; x < bmp.Width; x++)
{
c = bmp.GetPixel(x, y);
rgb = (int)((c.R + c.G + c.B) / 3);
bmp.SetPixel(x, y, System.Drawing.Color.FromArgb(rgb, rgb, rgb));
}
return bmp;
}
但是,我最终得到的 Bitmap 仍然具有 Format32bppRgb 的 PixelFormat 属性。
还有,
- 如何将 32 位彩色图像转换为 8 位彩色图像?
感谢您的任何意见!
相关。
- Convert RGB image to RGB 16-bit and 8-bit
- C# - How to convert an Image into an 8-bit color Image?
- C# Convert Bitmap to indexed colour format
- Color Image Quantization in .NET
- quantization (Reduction of colors of image)
- The best way to reduce quantity of colors in bitmap palette
【问题讨论】:
-
@anonymous - 你有很多链接,还有codeproject.com/Articles/66341/… 和code.msdn.microsoft.com/Convert-32-bit-PNGs-to-81ef8c81 你现在需要什么?
-
@SimonMourier,我在放弃赏金后解决了这个问题。所以,我现在什么都不需要了。
标签: c# .net system.drawing