C#でビットマップをα値固定で合成。ColorMatrixを使って合成。ちょっと遅い?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Bitmap backgroundImage = new Bitmap("a.jpg"); //背景 Bitmap foregroundImage = new Bitmap("b.jpg"); //正面 Graphics g = Graphics.fromImage(backGroundImage); ImageAttributes attr = new ImageAttributes(); ColorMatrix cMatrix = new ColorMatrix(); cMatrix[0, 0] = 1; cMatrix[1, 1] = 1; cMatrix[2, 2] = 1; cMatrix[3, 3] = alpha; // α cMatrix[4, 4] = 1; attr.SetColorMatrix(cMatrix); g.DrawImage(forgroundImage, new Rectangle(0, 0, backgroundImage.Width, backgroundImage.Height), // destnation image size 0, 0, foregroundImage.Width, foregroundImage.Height, // source image size GraphicsUnit.Pixel, attr); g.dispose(); |