c# gdi处理图片失真问题!!!
给图用添加文字水印后,图片的颜色会有所失真,整个图片与处理之前有一种被调暗的感觉。怎么样处理才不至于失真抽出主要的代码片段System.Drawing.ImageimgP...
给图用添加文字水印后,图片的颜色会有所失真,整个图片与处理之前有一种被调暗的感觉。怎么样处理才不至于失真
抽出主要的代码片段
System.Drawing.Image imgPhoto = System.Drawing.Image.FromFile(CurrentDirectory + "\\10.jpg");
picdiy pic = new picdiy();
Color cc = ColorTranslator.FromHtml("#FCF53A");
System.Drawing.Image webPic = pic.printFont(imgPhoto, "亲爱的小艾:", "方正卡通简体", 5,cc, 14, 268);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
webPic.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ClearContent();
Response.ContentType = "image/jpeg";
Response.BinaryWrite(ms.ToArray());
//释放资源...............
public Image printFont(Image pic,string str, string fontType, int fontWidth, Color fontColor, int x, int y)
{
Graphics grap = Graphics.FromImage(pic);
grap.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
grap.SmoothingMode = SmoothingMode.AntiAlias;
Font fot = new Font(fontType, fontWidth);
grap.DrawString(str, fot, new SolidBrush(fontColor), x, y);
return pic;
}
.
.
.在线等,懂的前辈,求指点!!!,请不要百度复制别人一大堆文章过来!
//g.CompositingQuality = CompositingQuality.HighQuality;
//g.SmoothingMode = SmoothingMode.HighQuality;
//g.InterpolationMode = InterpolationMode.HighQualityBicubic;
这几个属性也试过,但还是有所失真 展开
抽出主要的代码片段
System.Drawing.Image imgPhoto = System.Drawing.Image.FromFile(CurrentDirectory + "\\10.jpg");
picdiy pic = new picdiy();
Color cc = ColorTranslator.FromHtml("#FCF53A");
System.Drawing.Image webPic = pic.printFont(imgPhoto, "亲爱的小艾:", "方正卡通简体", 5,cc, 14, 268);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
webPic.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ClearContent();
Response.ContentType = "image/jpeg";
Response.BinaryWrite(ms.ToArray());
//释放资源...............
public Image printFont(Image pic,string str, string fontType, int fontWidth, Color fontColor, int x, int y)
{
Graphics grap = Graphics.FromImage(pic);
grap.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
grap.SmoothingMode = SmoothingMode.AntiAlias;
Font fot = new Font(fontType, fontWidth);
grap.DrawString(str, fot, new SolidBrush(fontColor), x, y);
return pic;
}
.
.
.在线等,懂的前辈,求指点!!!,请不要百度复制别人一大堆文章过来!
//g.CompositingQuality = CompositingQuality.HighQuality;
//g.SmoothingMode = SmoothingMode.HighQuality;
//g.InterpolationMode = InterpolationMode.HighQualityBicubic;
这几个属性也试过,但还是有所失真 展开
1个回答
展开全部
如果仅仅是给图片加文字修饰,不必要采用这么麻烦的操作;
string name = "测试一下";
string filename = HttpUtility.UrlEncode("测试1.jpg");
String fullpath = HttpContext.Current.Server.MapPath("images/img1.png");
string filenamesave = Server.MapPath("images/" + filename);
using (System.Drawing.Bitmap bitmaip = new System.Drawing.Bitmap(fullpath))
{
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmaip))
{
g.DrawString(name, new System.Drawing.Font("宋体", 30), System.Drawing.Brushes.Red, 182, 47);
}
bitmaip.Save(filenamesave, System.Drawing.Imaging.ImageFormat.Jpeg);
}
string name = "测试一下";
string filename = HttpUtility.UrlEncode("测试1.jpg");
String fullpath = HttpContext.Current.Server.MapPath("images/img1.png");
string filenamesave = Server.MapPath("images/" + filename);
using (System.Drawing.Bitmap bitmaip = new System.Drawing.Bitmap(fullpath))
{
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmaip))
{
g.DrawString(name, new System.Drawing.Font("宋体", 30), System.Drawing.Brushes.Red, 182, 47);
}
bitmaip.Save(filenamesave, System.Drawing.Imaging.ImageFormat.Jpeg);
}
追问
提了好久,才有个人来回答
首先谢谢
其实跟你的操作是基本一样的,不是麻烦,只是我为了方便利用管理与重复利用 ,把写文字的操作封到某个类里面,现在抽出代码片段出来才显多了点
另外你的这个代码,如果文字大点的的时候会出现明显的锯齿
追答
锯齿效果的处理 你可以查询下 GDI+ 关于双缓冲的使用
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询