Hi i have two Writablebitmap , one from jpg and another from png and use this method to mix color in a loop:
private 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));
}
My problem is in alpha channel, my watermark effect result is bad (quality)!
This is the original png.
This is the original jpg.
Any Help?
In this case you probably don't want the result to take on any alpha from the watermark, you want it to retain 100% of the opacity of the JPEG. Instead of setting the new alpha to from.A * amountFrom + to.A * percent
, just use from.A
.
Edit: In addition you want the percent
to be adjusted according to the alpha of the PNG. Here's your sample, updated:
private static Color Mix(Color from, Color to, float percent)
{
float amountTo = percent * to.A / 255.0;
float amountFrom = 1.0f - amountTo;
return Color.FromArgb(
from.A,
(byte)(from.R * amountFrom + to.R * amountTo),
(byte)(from.G * amountFrom + to.G * amountTo),
(byte)(from.B * amountFrom + to.B * amountTo));
}
I converted this code to Python and ran your sample images through it with 0.5 percent, here's the result:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With