我在一个asp.net应用中,服务器端要生成图片,发送道客户端。
代码框架如下:
private void Page_Load(object sender, System.EventArgs e)
{
imgOutput = new Bitmap(Width,Height,PixelFormat.Format24bppRgb); 
Graphics g = Graphics.FromImage(imgOutput);
Response.Clear();
//中间一些绘图函数
//...
imgOutput.Save(Response.OutputStream, ImageFormat.Gif);
imgOutput.Dispose();
Response.End();
}
现在发现生成的图像中,有些颜色填充的面,呈现很多的麻点状,不光滑,
有些颜色填充的面就很光滑。请问这个是怎么回事?试图改善gif图像质量,没有成功。
采用jpg输出,效果也不好,边界很模糊。

解决方案 »

  1.   

    可以设置图象质量的,具体查SDK文档
      

  2.   

    BitMap.CompositingQuality = Drawing.Drawing2D.CompositingQuality.HighQuality
      

  3.   

    试了一下。bitmap好像没有CompositingQuality 这个属性。
    Graphics才有这个属性。我设置了如下:
    Graphics g = Graphics.FromImage(imgOutput);
    g.CompositingQuality = CompositingQuality.HighQuality;
    不过发现没有什么改变:(
      

  4.   

    很早以前也试过,在asp.net里质量不高,后来改用vml自己画了.
    VML也是MS的.就是word里用的那种.试试吧
      

  5.   

    buy.cwecn.com小图就是我缩小的,你点进后看大图。质量都是很不错的。
      

  6.   

    /// <summary>
    /// 不失真获得缩微图
    /// </summary>
    /// <returns></returns>
    public bool GetThumbImg()
    {
    try
    {
    string imgpath;//原始路径
    if(imgsourceurl.IndexOf("\\",0)<0)//使用的是相对路径
    {
    imgpath=HttpContext.Current.Server.MapPath(imgsourceurl);//转化为物理路径
    }
    else
    {
    imgpath=imgsourceurl;
    }
    System.Drawing.Image sourceImage = System.Drawing.Image.FromFile(imgpath);
    int width = sourceImage.Width;
    int height = sourceImage.Height;
    if(thumbwidth<=0)
    {
    thumbwidth=120;
    }
    if(thumbwidth>=width)
    {
    return false;
    }
    else
    {
    //关键在这里:
    Image imgThumb=new System.Drawing.Bitmap(thumbwidth,height*thumbwidth/width);
    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(imgThumb);
    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
    g.DrawImage(sourceImage, new Rectangle(0, 0, thumbwidth,height*thumbwidth/width), 0, 0, width, height, GraphicsUnit.Pixel);
    string thumbpath="";
    sourceImage.Dispose();
    //myBitmap.Dispose();
    if(thumburl=="")
    {
    //File.Delete(HttpContext.Current.Server.MapPath(imgpath));
    thumbpath=imgpath;
    }

    if(thumbpath.IndexOf("\\",0)<0)//使用的是相对路径
    {
    thumbpath=HttpContext.Current.Server.MapPath(thumburl);//转化为物理路径
    }

    imgThumb.Save(thumbpath,ImageFormat.Jpeg);
    imgThumb.Dispose();
    return true;
    }
    }
    catch
    {
    throw;
    }
    }