2011-11-01 31 views
5

嗨,我有兩個Writablebitmap,一個來自JPG和另一名來自PNG,並使用此方法在一個循環混合顏色:Png over jpeg(水印效果)質量不好?

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通道,我的水印效果效果不好(質量)!

Result

這是原始PNG。

Original Pgn

這是原來的JPG。

Original Jpg

任何幫助?

+0

你能具體談談了「質量不好「,你想避免的水印? – ObscureRobot

+0

你的PNG是反鋸齒的,它只會在白色背景上看起來不錯。將它重新壓縮成jpeg是一炮而紅。沒有簡單的解決方案,水印不能使用抗鋸齒。 –

+0

我在想這與擁有一個jpg源碼有關。 JPEG上的有損壓縮利用心理 - 視覺模型使壓縮僞影更不明顯。在壓縮的圖像上重疊圖像會使該模型失控。解決此問題的最佳方法是使用無損壓縮的圖像源來處理水印和源圖像。 –

回答

5

在這種情況下,您可能不希望結果採用水印中的任何alpha,您希望它保留100%的JPEG不透明度。不要將新的alpha設置爲from.A * amountFrom + to.A * percent,只需使用from.A即可。

編輯:此外,你想percent根據PNG的alpha調整。這裏是你的樣品,更新:

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

+0

你以前說過。如果只有我可以單獨評分,請在圖片上+1。 – Candide

+0

@Ingenu,我想知道是否有人會注意到我的新頭像。我昨晚改了它。 –

+0

好,解決了,感謝Mark的工作! – JoeLoco