客户端通过iframe提交图片文件到服务器保存,但是图片保存下来有掉色的感觉,会有一个个的灰色的点。
看了保存下来的图片信息和原先的图片信息:原图片的位深度为24位,保存后的位深度为8位。
保存的格式,jpg,gif,上传什么就保存成什么格式都已经试过了。一样的结果。求帮忙
服务器保存方法:for (int i = 0; i < Files.Count; i++)
                    {
                        HttpPostedFile file = Files[i];
                        if (file.ContentLength > 0 && file.ContentType.IndexOf("image/") >= 0)
                        {
                            string fileNm = DateTime.Now.ToString("yyyyMMddHHmmss") + DateTime.Now.ToString("yyyy-MM-ddHHmmss") + ".gif";
                            fileName = ctx.Request.Params["File" + (i + 1) + "Name"] != null ?
                                            ctx.Request.Params["File" + (i + 1) + "Name"] : "";
                            fileInfo = ctx.Request.Params["File" + (i + 1) + "Info"] != null ?
                                            ctx.Request.Params["File" + (i + 1) + "Info"] : "";
                            filePath = dir + "/" + fileNm;
                            Image imgPhoto = Image.FromStream(file.InputStream, true);
                            Thread.Sleep(2000);
                            Bitmap bmPhoto = new Bitmap(imgPhoto.Width, imgPhoto.Height);
                            Graphics gbmPhoto = Graphics.FromImage(bmPhoto);
                            gbmPhoto.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                            gbmPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
                            gbmPhoto.Clear(Color.Transparent);
                            gbmPhoto.DrawImage(imgPhoto, new Rectangle(0, 0, imgPhoto.Width, imgPhoto.Height), new Rectangle(0, 0, imgPhoto.Width, imgPhoto.Height), GraphicsUnit.Pixel);
                            bmPhoto.Save(map + "/" + dir + "/" + fileNm, ImageFormat.Gif);
                            imgPhoto.Dispose();
                            gbmPhoto.Dispose();
                            bmPhoto.Dispose();                            int no = db.ExecuteSQL("insert into imgUpload values('" + fileName + "', '" + fileInfo + "', '" + filePath + "', '" + DateTime.Now.ToString("yyyy-MM-dd") + "')");
                            if (no < 0)
                                errmsg += "图片:" + fileName + "上传失败;";
                        }
                    }

解决方案 »

  1.   

    http://blog.csdn.net/johnsuna/archive/2007/08/30/1765822.aspx
      

  2.   

    gbmPhoto.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;反锯齿=>"模糊" 去掉 Bitmap bmPhoto = new Bitmap(imgPhoto.Width, imgPhoto.Height);
    这个也去掉 
    在看看效果你把图生成缩略图在上传看看。丢失的应该没那么厉害
      

  3.   

    生成的缩略图,除非像素在200内,否则还是比较明显的。
    我想保存原图大小的。
    直接Image imgPhoto = Image.FromStream(file.InputStream);
    然后 imgPhoto.save();也尝试过。还是一样的结果