我會後所有的代碼來完成。目前我知道這很難看,但這是爲了快速需要。 我正常的地圖從通常的紫色格式轉換爲橙色格式。這只是渠道交換。
![Converting normal map from purple format to orange format](https://i.stack.imgur.com/fYd9O.jpg)
我使用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");
並非所有枚舉的像素格式實際上都支持。其餘的代碼很奇怪 - 爲什麼不清楚你想要的顏色? – TaW
PixelFormat枚舉的像素格式實際上並未完全實現。像16bppGrayScale一樣。回想起來,GDI +的設計假設隨着顯示技術的改進,一些像素格式將變得可用。這種情況並沒有發生,液晶顯示器實際上距CRT顯着一步之遙,還沒有接近尾聲。支持16bpp灰度的監視器確實存在,您可以在當地醫院的放射科找到它們。你知道他們收到賬單後的花費。 –