I have two System.Windows.Media.Color (a and b)and need to get a and put over b to simulate tranparency. to use in my merge method:
public static Image Merge(Image a,Image b)
{
for(int x=0;x < b.Width;x++ )
{
for (int y = 0; y < b.Height; y++)
{
a.SetPixel(x, y, b.GetPixel(x, y));
}
}
return a;
}
Help Thank's!!
Solution:
public static Image Merge(Image a,Image b)
{
for(int x=0;x < b.Width;x++ )
{
for (int y = 0; y < b.Height; y++)
{
a.SetPixel(x, y, Mix(a.GetPixel(x, y), b.GetPixel(x, y), .5f));
//a.SetPixel(x, y,b.GetPixel(x, y));
}
}
return a;
}
public static Color Mix(Color from, Color to, float percent)
{
float amountFrom = 1.0f - percent;
return Color.FromArgb(
(byte)(from.A * amountFrom + to.A * percent),
(byte)(from.R * amountFrom + to.R * percent),
(byte)(from.G * amountFrom + to.G * percent),
(byte)(from.B * amountFrom + to.B * percent));
}
I found one rounding error in Mix Method, solve when use Math.Round():
public static Color Mix(Color from, Color to, float percent) { float amountFrom = 1.0f - percent;
return Color.FromArgb(
(byte)Math.Round(from.A * amountFrom + to.A * percent),
(byte)Math.Round(from.R * amountFrom + to.R * percent),
(byte)Math.Round(from.G * amountFrom + to.G * percent),
(byte)Math.Round(from.B * amountFrom + to.B * percent));
}