public byte[] MarkImage(List <WatermarkItem> watermarkCollection) { byte[] file = null; using (Stream inStream = new MemoryStream()) using (Image image = resizeImage(_ImgPhoto, ScaleImage(_ImgPhoto, 640, 480))) { for (int i = 0; i < watermarkCollection.Count; i++) { WatermarkItem item = watermarkCollection[i]; using (Image watermarkImage = item.Image) using (Graphics imageGraphics = Graphics.FromImage(image)) using (TextureBrush watermarkBrush = new TextureBrush(watermarkImage)) { //item.Update(resizeImage(_ImgPhoto, ScaleImage(watermarkCollection[i].Image, 640 / 4, 480 / 4))); WatermarkPoint point = new WatermarkPoint(watermarkCollection[i], image.Width, image.Height); int x = point.X; int y = point.Y; watermarkBrush.TranslateTransform(x, y); imageGraphics.FillRectangle(watermarkBrush, new Rectangle(new Point(x, y), new Size(watermarkImage.Width + 1, watermarkImage.Height))); } } image.Save(inStream, _ImgFormat); file = Helper.ToByteArray(inStream); } return(file); }
public WatermarkPoint(WatermarkItem watermark, int phWidth, int phHeight) { int wmWidth = watermark.Image.Width; int wmHeight = watermark.Image.Height; switch (watermark.ContentAlignment) { case ContentAlignment.BottomCenter: X = (phWidth / 2) - (wmWidth / 2); Y = (phHeight - wmHeight) - 10; break; case ContentAlignment.BottomLeft: X = 10; Y = (phHeight - wmHeight) - 10; break; case ContentAlignment.BottomRight: X = ((phWidth - wmWidth) - 10); Y = (phHeight - wmHeight) - 10; break; case ContentAlignment.MiddleCenter: X = (phWidth / 2) - (wmWidth / 2); Y = (phHeight / 2) - (wmHeight / 2); break; case ContentAlignment.MiddleLeft: X = 10; Y = (phHeight / 2) - (wmHeight / 2); break; case ContentAlignment.MiddleRight: X = ((phWidth - wmWidth) - 10); Y = (phHeight / 2) - (wmHeight / 2); break; case ContentAlignment.TopCenter: X = (phWidth / 2) - (wmWidth / 2); Y = 10; break; case ContentAlignment.TopLeft: X = 10; Y = 10; break; case ContentAlignment.TopRight: X = ((phWidth - wmWidth) - 10); Y = 10; break; } }
public WatermarkPoint(WatermarkItem watermark) : this(watermark, 800, 600) { }