我需要通过特殊方式为照片添加水印.我知道怎么做,但我不知道如何做到这一点与文章http://www.photoshopessentials.com/photo-effects/copyright/相同
这是添加水印的方法.如何更改它以获得带有水印的图像,例如上面的文章?
public static Bitmap AddWatermark(this Bitmap originalImage, Bitmap watermarkImage, WatermarkLocationEnum location)
{
int offsetWidth;
int offsetHeight;
if ((watermarkImage.Width > originalImage.Width) | (watermarkImage.Height > originalImage.Height))
throw new Exception("The watermark must be smaller than the original image.");
Bitmap backgroundImage = new Bitmap((Bitmap)originalImage.Clone());
Bitmap image = new Bitmap(backgroundImage.Width, backgroundImage.Height);
Graphics graphics = Graphics.FromImage(image);
offsetWidth = GetOffsetWidth(image.Width, watermarkImage.Width, location);
offsetHeight = GetOffsetHeight(image.Height, watermarkImage.Height, location);
watermarkImage.SetResolution(backgroundImage.HorizontalResolution, backgroundImage.VerticalResolution);
offsetWidth = Math.Max(offsetWidth - 1, 0);
offsetHeight = Math.Max(offsetHeight - 1, 0);
graphics.DrawImage(watermarkImage, offsetWidth, offsetHeight); …Run Code Online (Sandbox Code Playgroud) 我试图使用TextureBrush在尺寸宽度= 1000,高度= 16的矩形区域上平铺图像(16x16)以获得像UI一样的条带.
Rectangle myIconDrawingRectangle = new Rectangle(x, y, 1000, 16);
using (TextureBrush brush = new TextureBrush(myIcon, WrapMode.Tile))
{
e.Graphics.FillRectangle(brush, myIconDrawingRectangle );
}
Run Code Online (Sandbox Code Playgroud)
当我用x = 0绘制时,y = 0平铺从(0,0)开始按预期发生.
当我用x = 0绘制时,y = 50平铺从(0,50)开始,但绘制矩形不是从图像的开头开始.它从图像的裁剪部分开始,然后重复.
怎么解决这个?
PS:我不想在DrawImage上重复手动循环.