Graphics.DrawString() 生成的图片质量比原图片差很多
System.Drawing.Bitmap addBitmap = new Bitmap(StringFileName);
Graphics G = Graphics.FromImage(addBitmap);
G.DrawImage(addBitmap, 0, 0, addBitmap.Width, addBitmap.Height);
G.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
G.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
G.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
G.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
G.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
G.DrawString(StringSYName, richTextBox1.Font, new SolidBrush(richTextBox1.ForeColor), Left, Top);
G.Dispose();
addBitmap.Save("文件名")
源文件的大小有110多KB,很清楚的一张图片,加文字水印后,保存后的新文件,只有30K的样子,有点模糊,文件质量大不如以前,
请问有什么办法让加水印后的图片和源图片一样清晰,效果一样的不错,图片文件大小也和原来差不多!
------解决方案--------------------
保存的时候要设计图片质量的
Bitmap bitmap = new Bitmap(width, height);
//修改图片保存质量
ImageCodecInfo myImageCodecInfo = GetEncoderInfo("image/jpeg");
myEncoder = Encoder.Quality;
myEncoderParameters = new EncoderParameters(1);
//图片质量等级
myEncoderParameter = new EncoderParameter(myEncoder, 100L);
myEncoderParameters.Param[0] = myEncoderParameter;
//建立做图纸
Graphics g = Graphics.FromImage(bitmap);
g.Clear(Color.White);
//做图质量
g.SmoothingMode = SmoothingMode.AntiAlias;
//图像输出
bitmap.Save(Response.OutputStream, myImageCodecInfo, myEncoderParameters);