我目前正在使用 C# 创建某种游戏,并尝试为玩家创建服装。我想做布料设计,让玩家选择颜色。
我从 TibiaME (tibiame.com) 的游戏文件中拍摄了照片,它几乎满足了我的要求。
如何为该表格填充颜色?当我尝试替换某种颜色时,它不起作用,因为它在每个地方都不相同。阴影看起来很酷:P
最佳答案
对图像进行着色(着色)的最简单(也是最快)的方法是使用 ColorMatrix .
这是使用九种颜色对原件进行着色的结果:
请注意,我已经对发布的图像进行了 Photoshop 处理,使其中心部分周围透明;只使用原来的看起来像这样..:
((右下的小故障是原来的..))
这是一个返回图像着色版本列表的函数,列表中的每种颜色对应一个......:
List<Bitmap> TintImages(Bitmap bmp0, List<Color> colors )
{
List<Bitmap> tinted = new List<Bitmap>();
Size sz = bmp0.Size;
float f = 256f;
for (int i = 0; i < colors.Count; i++)
{
float r = colors[i].R / f;
float g = colors[i].G / f;
float b = colors[i].B / f;
float[][] colorMatrixElements = {
new float[] {r, 0, 0, 0, 0}, // red scaling factor of
new float[] {0, g, 0, 0, 0}, // green scaling factor
new float[] {0, 0, b, 0, 0}, // blue scaling factor
new float[] {0, 0, 0, 1, 0}, // alpha scaling factor
new float[] {0, 0, 0, 0, 1}}; // no further translations
ImageAttributes imageAttributes = new ImageAttributes();
ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes.SetColorMatrix(
colorMatrix,
ColorMatrixFlag.Default,
ColorAdjustType.Bitmap);
Bitmap bmp = new Bitmap(sz.Width, sz.Height);
using (Graphics gr = Graphics.FromImage(bmp))
{
gr.DrawImage(bmp0, new Rectangle(0, 0, sz.Width, sz.Height),
0, 0, sz.Width, sz.Height, GraphicsUnit.Pixel, imageAttributes);
tinted.Add(bmp);
}
}
return tinted;
}
关于C# 用阴影给图像着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51526858/