gpt4 book ai didi

c# - png over jpeg(水印效果)质量差?

转载 作者:太空狗 更新时间:2023-10-29 23:17:43 26 4
gpt4 key购买 nike

您好,我有两个 Writablebitmap,一个来自 jpg,另一个来自 png,并使用此方法在循环中混合颜色:

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

我的问题是在 alpha channel 中,我的水印效果很差(质量)!

Result

这是原始png。

Original Pgn

这是原始的jpg。

Original Jpg

有什么帮助吗?

最佳答案

在这种情况下,您可能不希望结果采用水印中的任何 alpha,您希望它保留 JPEG 的 100% 不透明度。不要将新的 alpha 设置为 from.A * amountFrom + to.A * percent,只需使用 from.A

编辑:此外,您希望根据 PNG 的 alpha 调整 percent。这是您的示例,已更新:

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

关于c# - png over jpeg(水印效果)质量差?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7972247/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com