网上的代码都差不多
找出最常用的几句:
//原始图片 都是jpeg格式
Image originalImage = Image.FromFile(...);
//水印图片
Image waterMarkImage = Image.FromFile(...);
Graphics g = Graphics.FromImage(originalImage);
g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
//画水印
g.DrawImage(waterMarkImage,...);
originalImage.Save("新图片路径",ImageFormat.Jpeg);问题是这样:
我用 原始图片为8.6mb的图片 
加上水印保存之后
只有1mb多一点 
怎么样才能加水印而不改变图片的其他属性(大小)呢?

解决方案 »

  1.   

    http://www.cnblogs.com/jiangguanghe/archive/2008/09/28/1301562.html
      

  2.   


    http://blog.csdn.net/fengyarongaa/article/details/7175512
    我博客using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.IO;
    using System.Drawing;
    using System.Drawing.Imaging;/// <summary>
    /// PictureHandler 的摘要说明
    /// </summary>
        public class PicHandler : IHttpHandler
        {
            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "text/plain";
       
                string imgUrl = context.Request.PhysicalPath;//得到当前处理图片的物理路径
                if (File.Exists(imgUrl))
                {
                    Image img = Image.FromFile(imgUrl);//通过图片路径得到图片对象
                    Image watering = Image.FromFile(context.Server.MapPath("~/themes/images/water.jpg"));//得到数字水印图片
                    Graphics g = Graphics.FromImage(img);//通过图片对象创建画布
                    g.DrawImage(watering, new Rectangle(img.Width - watering.Width, img.Height - watering.Height, watering.Width, watering.Height), 0, 0, watering.Width, watering.Height, GraphicsUnit.Pixel);//画图
                    context.Response.ContentType = "image/jpeg";//设置图片的格式
                    img.Save(context.Response.OutputStream, ImageFormat.Jpeg);//把图片保存在输出流中
                    g.Dispose();//销毁画布
                    img.Dispose();//销毁图片
                    context.Response.End();
                }
                else
                {
                    Image defaultimg = Image.FromFile(context.Server.MapPath("~/themes/images/water.jpg"));//通过图片路径得到默认图片对象
                    Image watering = Image.FromFile(context.Server.MapPath("~/themes/images/water.jpg"));//得到数字水印图片
                    Graphics g = Graphics.FromImage(defaultimg);//通过图片对象创建画布
                    g.DrawImage(watering, new Rectangle(defaultimg.Width - watering.Width, defaultimg.Height - watering.Height, watering.Width, watering.Height), 0, 0, watering.Width, watering.Height, GraphicsUnit.Pixel);//画图                context.Response.ContentType = "image/jpeg";//设置图片的格式
                    defaultimg.Save(context.Response.OutputStream, ImageFormat.Jpeg);
                    g.Dispose();
                    defaultimg.Dispose();
                    context.Response.End();
                }        }
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
      

  3.   

    你代码中指定了Jpeg格式,并用了默认的图像品质:
    originalImage.Save("新图片路径",ImageFormat.Jpeg);1、试试保留原照片的格式xxx,比如:
    originalImage.Save("新图片路径.xxx");2、或调高图像品质的JPEG压缩(一般不需要,除非有高图像品质要求)。