.net 加水印 图片变大很多 解决方法

 /// 给图片加水印 中国红木网 

        /// </summary>
        /// <param name="originalImg"></param>
        /// <param name="waterImg"></param>
        /// <param name="trbl"></param>
        /// <returns></returns>
        public static Image WatermarkImage(Image originalImg, Image waterImg, WatermarkTRBL trbl)
        {
 
            Image image = (Image)originalImg.Clone();
            using (Graphics g = Graphics.FromImage(image))
            {
                Rectangle r = new Rectangle();
                r.Height = waterImg.Height;
                r.Width = waterImg.Width;
                if (trbl.Top != null)
                {
                    r.Y = (int)trbl.Top;
                }
 
                if (trbl.Right != null)
                {
                    r.X = originalImg.Width - waterImg.Width - (int)trbl.Right;
                }
 
                if (trbl.Bottom != null)
                {
                    r.Y = originalImg.Height - waterImg.Height - (int)trbl.Bottom;
                }
 
                if (trbl.Left != null)
                {
                    r.X = (int)trbl.Left;
                }
 
                g.DrawImage(waterImg, r, 0, 0, waterImg.Width, waterImg.Height, GraphicsUnit.Pixel);
            }
 
            return image;
        }

Bitmap b = new Bitmap(image.Width, image.Height,PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(b);

g.Clear(Color.White);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default;
g.DrawImage(image, 0, 0, image.Width, image.Height);

 

高质量 用普通模式

 

.net 加水印 图片变大很多 解决方法,布布扣,bubuko.com

.net 加水印 图片变大很多 解决方法

上一篇:Jquery Drag and Drop


下一篇:Social Network 社交网络分析