Png over jpeg (watermark effect) poor quality?

Hi, I have two Writablebitmap, one from jpg and the other from png, and use this method to mix colors 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 the alpha channel, my result of the watermark effect is bad (quality)!

Result

This is the original png.

Original pgn

This is the original jpg.

Original Jpg

Any help?

+5
source share
1 answer

In this case, you probably do not want the result to accept any alpha from the watermark, you want to preserve 100% opacity of the JPEG. Instead of setting a new alpha, from.A * amountFrom + to.A * percentjust use from.A.

: , , percent PNG. , :

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)); 
}

Python 0,5%, :

enter image description here

+5

All Articles