Draw image on top of another image with blending mode color

前端 未结 3 754
刺人心
刺人心 2021-02-09 07:34

In Photoshop you can select \"Color\" (the second from the bottom) to set the blending mode to the next lower layer:

3条回答
  •  北海茫月
    2021-02-09 07:55

    Here's a safe (and slower) version of the accepted answer for completeness.

            using (var lower = new Bitmap(@"lower.png"))
            using (var upper = new Bitmap(@"upper.png"))
            using (var output = new Bitmap(lower.Width, lower.Height))
            {
                var width = lower.Width;
                var height = lower.Height;
    
                for (var i = 0; i < height; i++)
                {
                    for (var j = 0; j < width; j++)
                    {
                        var upperPixel = upper.GetPixel(j, i);
                        var lowerPixel = lower.GetPixel(j, i);
    
                        var lowerColor = new HSLColor(lowerPixel.R, lowerPixel.G, lowerPixel.B);
                        var upperColor = new HSLColor(upperPixel.R, upperPixel.G, upperPixel.B) {Luminosity = lowerColor.Luminosity};
                        var outputColor = (Color)upperColor;
    
                        output.SetPixel(j, i, outputColor);
                    }
                }
    
                // Drawing the output image
            }
    

提交回复
热议问题