我想要做的是發生事件後,我將所有的箭頭圖片設置爲紫色。着色位圖不準確(我已經看過:如何在C#.NET中更改圖像的像素顏色)
首先,我讓所有帶箭頭的pictureboxes的列表:
List<PictureBox> arrows = new List<PictureBox>();
foreach (var item in Controls.OfType<PictureBox>())
{
if (item.Name.StartsWith("arrow"))
{
arrows.Add(item);
}
}
這是我使用的彩色圖片代碼:
System.Drawing.Color purple = System.Drawing.Color.Purple;
foreach (var item in arrows)
{
Bitmap bmp = new Bitmap(item.Image, item.Height, item.Width);
for (int i = 0; i < item.Height; i++)
{
for (int j = 0; j < item.Width; j++)
{
var actualColor = bmp.GetPixel(i, j).ToArgb();
var purpleA = bmp.GetPixel(i, j).A;
if (actualColor != System.Drawing.Color.White.ToArgb())
{
bmp.SetPixel(i, j, System.Drawing.Color.FromArgb(purpleA, purple));
} else
{
bmp.SetPixel(i, j, System.Drawing.Color.FromArgb(actualColor));
}
}
}
item.Image = bmp;
}
如何準確着色圖像?此刻,紫色真的很糟糕。我需要它與黑色箭頭完全相同,而不是黑色,我需要它是紫色的。
注意:當我將它放入圖片框時,我調整了黑色箭頭圖像的大小,因此在黑色和紫色箭頭的形狀上大小相同。我上傳了帶有屏幕截圖的紫色箭頭,黑色箭頭來自我的電腦。這就是爲什麼他們的尺寸不一樣。
你是什麼意思?實際問題在哪裏? – ViRuSTriNiTy
我發佈了圖片。看看紫色畫得有多糟糕。我需要箭頭完全相同,但不是黑色,我需要它是紫色的。 – Mathijs
Alpha通道必須存在問題。嘗試將紅色綠色和藍色部分與255比較,然後是白色。 – ViRuSTriNiTy