我将发布所有代码。我知道它目前很丑,但它是为了快速需要。
我正在将法线贴图从通常的紫色格式转换为橙色格式。这只是频道交换。
我正在使用 AForge 框架来更轻松地执行此操作。我从输入图片中提取所需的通道(只有红色要交换)。我克隆它,它也为 RGB 条目添加了一个 alpha 通道。然后我修改副本的通道以获得新的图像。
问题在于需要新的纯白色和纯黑色图像的红色和蓝色通道。
我需要在“Format8bppIndexed”中创建一个图像(这会很好),或者在“Format16bppGrayScale”中创建一个更糟糕的图像。 SetPixel 不接受索引格式。
//Opening the normal map (RGB)
Bitmap i = AForge.Imaging.Image.FromFile("C:/Users/KuroTenshi/WD/normalblue/07_bloom_doublemetaldoor_d_high_n.bmp");
//Extract the red channel, that will be put in an alpha channel
ExtractChannel filterR = new ExtractChannel(RGB.R);
Bitmap r = filterR.Apply(i);
//Clone the input image to have a base for the output (it's converted to ARGB)
Bitmap j = AForge.Imaging.Image.Clone(i);
//Extract channels to modify
ExtractChannel filterR2 = new ExtractChannel(RGB.R);
ExtractChannel filterB2 = new ExtractChannel(RGB.B);
ExtractChannel filterA2 = new ExtractChannel(RGB.A);
Bitmap r2 = filterR2.Apply(j);
Bitmap b2 = filterB2.Apply(j);
Bitmap a2 = filterA2.Apply(j);
//Putting input's red channel into output's alpha channel
a2 = r;
//Creating a white Bitmap for the output's red channel
Bitmap bmp = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format16bppGrayScale);
bmp.SetPixel(0, 0, Color.FromArgb(255, 255, 255));
bmp = new Bitmap(bmp, i.Width, i.Height);
r2 = bmp;
//Creating a black Bitmap for the output's blue channel
Bitmap bmp2 = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format16bppGrayScale);
bmp2.SetPixel(0, 0, Color.FromArgb(0,0,0));
bmp2 = new Bitmap(bmp2, i.Width, i.Height);
b2 = bmp2;
//Replace channels
ReplaceChannel replaceFilter = new ReplaceChannel(RGB.A, a2);
replaceFilter.ApplyInPlace(j);
replaceFilter = new ReplaceChannel(RGB.R, r2);
replaceFilter.ApplyInPlace(j);
replaceFilter = new ReplaceChannel(RGB.B, b2);
replaceFilter.ApplyInPlace(j);
//Save output
j.Save("C:/Users/KuroTenshi/WD/normalblue/07_bloom_doublemetaldoor_d_high_n2.bmp");