Original Post
Hi, i have a function to copy it and modify the color of each point, but the alpha is not copied and the background become black (but at the base it's transparency) to see the picture i manipulate : http://tech.daaboo.net/down/font.tga the color manipulation work well, the problem is only with alpha the code : have you an idea ? thanks Killan [Edited by - killan on June 4, 2006 3:43:49 PM]
public static Texture TextureChangeColor(Texture t, int r, int g, int b)
{
Color colo;
int br, bg, bb;
SurfaceDescription desc = t.GetLevelDescription(0);
SurfaceDescription s = t.GetLevelDescription(0);
Texture tex = new Texture(t.Device, desc.Width, desc.Height, 1, 0, t.Device.DisplayMode.Format, Pool.Managed);
uint[,] data = (uint[,])t.LockRectangle(typeof(uint), 0,
LockFlags.None, s.Width, s.Height);
uint[,] datadest = (uint[,])tex.LockRectangle(typeof(uint), 0,
LockFlags.None, s.Width, s.Height);
for (int i = 0; i < s.Width; i++)
{
for (int j = 0; j < s.Height; j++)
{
colo = Color.FromArgb((int)data[i,j]);
if (r > 0)
{
if (colo.R + r <= byte.MaxValue) br = colo.R + r;
else br = byte.MaxValue;
}
else if (r < 0)
{
if (colo.R + r >= byte.MinValue) br = colo.R + r;
else br = byte.MinValue;
}
else br = colo.R;
if (g > 0)
{
if (colo.G + r <= byte.MaxValue) bg = colo.G + g;
else bg = byte.MaxValue;
}
else if (g < 0)
{
if (colo.G + g >= byte.MinValue) bg = colo.G + g;
else bg = byte.MinValue;
}
else bg = colo.G;
if (b > 0)
{
if (colo.B + r <= byte.MaxValue) bb = colo.B + b;
else bb = byte.MaxValue;
}
else if (b < 0)
{
if (colo.B + b >= byte.MinValue) bb = colo.B + b;
else bb = byte.MinValue;
}
else bb = colo.B;
datadest[i,j] = (uint)Color.FromArgb(colo.A,br,bg,bb).ToArgb();
}
}
t.UnlockRectangle(0);
tex.UnlockRectangle(0);
return tex;
}