public override Image Apply(Image img) { using (img) { return(ColorMatrixManager.Alpha(Value, Addition).Apply(img)); } }
public override Bitmap Apply(Bitmap bmp) { using (bmp) { return(ColorMatrixManager.Alpha(Value, Addition).Apply(bmp)); } }
public override Bitmap Apply(Bitmap bmp) { if (Opacity < 1 || (SizeMode != DrawImageSizeMode.DontResize && Size.Width <= 0 && Size.Height <= 0)) { return(bmp); } string imageFilePath = Helpers.ExpandFolderVariables(ImageLocation, true); if (!string.IsNullOrEmpty(imageFilePath) && File.Exists(imageFilePath)) { using (Bitmap bmpWatermark = ImageHelpers.LoadImage(imageFilePath)) { if (bmpWatermark != null) { if (RotateFlip != ImageRotateFlipType.None) { bmpWatermark.RotateFlip((RotateFlipType)RotateFlip); } Size imageSize; if (SizeMode == DrawImageSizeMode.AbsoluteSize) { int width = Size.Width == -1 ? bmp.Width : Size.Width; int height = Size.Height == -1 ? bmp.Height : Size.Height; imageSize = ImageHelpers.ApplyAspectRatio(width, height, bmpWatermark); } else if (SizeMode == DrawImageSizeMode.PercentageOfWatermark) { int width = (int)Math.Round(Size.Width / 100f * bmpWatermark.Width); int height = (int)Math.Round(Size.Height / 100f * bmpWatermark.Height); imageSize = ImageHelpers.ApplyAspectRatio(width, height, bmpWatermark); } else if (SizeMode == DrawImageSizeMode.PercentageOfCanvas) { int width = (int)Math.Round(Size.Width / 100f * bmp.Width); int height = (int)Math.Round(Size.Height / 100f * bmp.Height); imageSize = ImageHelpers.ApplyAspectRatio(width, height, bmpWatermark); } else { imageSize = bmpWatermark.Size; } Point imagePosition = Helpers.GetPosition(Placement, Offset, bmp.Size, imageSize); Rectangle imageRectangle = new Rectangle(imagePosition, imageSize); if (AutoHide && !new Rectangle(0, 0, bmp.Width, bmp.Height).Contains(imageRectangle)) { return(bmp); } using (Graphics g = Graphics.FromImage(bmp)) { g.InterpolationMode = ImageHelpers.GetInterpolationMode(InterpolationMode); g.PixelOffsetMode = PixelOffsetMode.Half; g.CompositingMode = CompositingMode; if (Tile) { using (TextureBrush brush = new TextureBrush(bmpWatermark, WrapMode.Tile)) { brush.TranslateTransform(imageRectangle.X, imageRectangle.Y); g.FillRectangle(brush, imageRectangle); } } else if (Opacity < 100) { using (ImageAttributes ia = new ImageAttributes()) { ColorMatrix matrix = ColorMatrixManager.Alpha(Opacity / 100f); ia.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); g.DrawImage(bmpWatermark, imageRectangle, 0, 0, bmpWatermark.Width, bmpWatermark.Height, GraphicsUnit.Pixel, ia); } } else { g.DrawImage(bmpWatermark, imageRectangle); } } } } } return(bmp); }