2017-04-16 96 views
0

我創建了一個繪圖模塊,可以在其中繪製背景圖像。 「圖紙」是一個透明的PNG,當我保存圖像時,我將它合併在一起。iOS保存組合圖像

但是,這裏的問題是,對比度有時不好看(見下圖)。

之前(油漆模式):

enter image description here

後(生病時乘兩個圖像):

enter image description here

(很難看到任何黃色)。

我乘以兩個圖像:

UIGraphicsBeginImageContextWithOptions(size, false, 0.0) 
    bottomImage!.draw(in: CGRect(x: 0,y: 0,width: size.width, height: size.height)) 
    topImage!.draw(in: CGRect(x: 0,y: 0,width: size.width, height: size.height), blendMode: CGBlendMode.multiply , alpha: 1.0) 
    combinedImage = UIGraphicsGetImageFromCurrentImageContext() 
    UIGraphicsEndImageContext() 

任何想法我如何能得到更好的顏色?

+0

你爲什麼使用'.multiply'?這似乎很愚蠢。 – matt

+0

我想結合兩個圖像的內容。還有什麼不該用的? – derdida

+0

那麼,有[CGBlendMode的文檔](https://developer.apple.com/reference/coregraphics/cgb​​lendmode)。如果你只是想合併它們,'.normal'似乎是一個明顯的選擇。 – DarkDust

回答

1

剪下關於混合模式的部分。只需將「繪畫」(topImage)直接繪製到背景上(bottomImage)即可。

+0

啊,這很容易 - 生病猜猜我用「白色」背景(而不是一個明確的PNG作爲頂部圖像)繪製時使用繁殖 - 然後我需要繁殖(當然) - 感謝您的答案! – derdida