gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
c#将索引图转灰度图的代码
- User
c#将索引图转灰度图的代码
- Assistant
以下是将索引图(Palette格式)转为灰度图的C#代码:
csharp - User
使用c#将索引图转灰度图的程序代码
- Assistant
以下是使用C#将索引图转换为灰度图的代码示例:
csharpusing System; using System.Drawing; using System.Drawing.Imaging; public class ConvertIndexToGray { public static Bitmap ConvertToGray(Bitmap indexImage, ColorPalette palette) { Bitmap grayImage = new Bitmap(indexImage.Width, indexImage.Height, PixelFormat.Format8bppIndexed); grayImage.Palette = palette; for (int y = 0; y < indexImage.Height; y++) { for (int x = 0; x < indexImage.Width; x++) { Color pixelColor = indexImage.GetPixel(x, y); byte grayValue = (byte)(0.299 * pixelColor.R + 0.587 * pixelColor.G + 0.114 * pixelColor.B); grayImage.SetPixel(x, y, Color.FromArgb(grayValue, grayValue, grayValue)); } } return grayImage; } }