图片水印效果

        #region 创建水印 [图片水印] [坐标位置]
        /// <summary>
        /// 创建水印 [图片水印] [坐标位置]
        /// </summary>
        /// <param name="originalImg">源图片</param>
        /// <param name="watermarkImg">水印图片</param>
        /// <param name="x">X坐标</param>
        /// <param name="y">Y坐标</param>
        /// <returns>带水印的图片</returns>
        public static Image CreateWatermark(Image originalImg, Image watermarkImg, int x, int y)
        {
            Bitmap bitmap = new Bitmap(originalImg.Width, originalImg.Height, PixelFormat.Format24bppRgb);
            bitmap.MakeTransparent();
            Graphics originalGraphics = Graphics.FromImage(bitmap);
            originalGraphics.SmoothingMode = SmoothingMode.AntiAlias;
            originalGraphics.DrawImage(originalImg, new Rectangle(0, 0, originalImg.Width, originalImg.Height), 0, 0, originalImg.Width, originalImg.Height, GraphicsUnit.Pixel);
            originalGraphics.Dispose();
            bitmap.SetResolution(originalImg.HorizontalResolution, originalImg.VerticalResolution);
            Graphics watermarkGraphics = Graphics.FromImage(bitmap);
            watermarkGraphics.DrawImage(watermarkImg, new Rectangle(x, y, watermarkImg.Width, watermarkImg.Height), 0, 0, watermarkImg.Width, watermarkImg.Height, GraphicsUnit.Pixel);
            watermarkGraphics.Dispose();
            return bitmap;
        }
        #endregion
显示效果如下图中的右下脚的 小蝴蝶图标

posted on 2007-09-15 17:38  RevengeBoy  阅读(572)  评论(1编辑  收藏  举报

导航