我试图用另一个图像覆盖图像以提供水印,但它必须覆盖整个源图像。问题是所提供的水印是600x600并且源图像可以具有任何尺寸和纵横比。到目前为止,它还没有完全覆盖源图像。
答案 0 :(得分:1)
我这样解决了(以非常简单的方式)。
private void button1_Click(object sender, EventArgs e)
{
var image = new Bitmap( this.pictureBox1.Image.Width, this.pictureBox1.Image.Height);
var rect = new Rectangle(0, 0, this.pictureBox1.Image.Width, this.pictureBox1.Image.Height);
Graphics graphics = Graphics.FromImage(image);
graphics.DrawImage(this.pictureBox1.Image, 0, 0);
var waterMarkImage = new Bitmap(this.pictureBox2.Image.Width, this.pictureBox2.Image.Height);
for (int y = 0; y < waterMarkImage.Height; y++)
{
for (int x = 0; x < waterMarkImage.Width; x++)
{
var color = (this.pictureBox2.Image as Bitmap).GetPixel(x, y);
color = Color.FromArgb(50, color.R, color.G, color.B);
waterMarkImage.SetPixel(x, y, color);
}
}
graphics.DrawImage(waterMarkImage, rect);
this.pictureBox3.Image = image;
}
在pictureBox1中我加载了主图像。在pictureBox2中,我加载了“水印”。在事件处理程序中,我创建了结果图像(第一个主图像,然后是第二个)并将其加载到pictureBox3中。为了获得水印效果,我减少了颜色的alpha分量(我将其设置为50)。