C# 图片上写字 图片高质量输出

 C#  图片上写字  图片高质量输出

 

一、引用命名空间

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Drawing;
using System.Runtime.InteropServices.ComTypes;

 

二、程序

 protected void Page_Load(object sender, EventArgs e)
        {
            initPage();
        }
        protected void initPage()
        {
           string url = Server.MapPath("upload") +"//"+ "soufunquan.jpg";

            string url = "d:/quan.jpg";

            String src = url;   //源图像文件的绝对路径
            String dest = "d:/xxx.jpg";    //生成的缩略图图像文件的绝对路径 
            int thumbWidth=624;    //要生成的缩略图的宽度 
            int thumbHeight = 306;
            System.Drawing.Image image = System.Drawing.Image.FromFile(url); //利用Image对象装载源图像 
            //接着创建一个System.Drawing.Bitmap对象,并设置你希望的缩略图的宽度和高度。 
            int srcWidth=image.Width; 
            int srcHeight=image.Height;  
            //int thumbHeight=(srcHeight/srcWidth)*thumbWidth; 
            Bitmap bmp = new Bitmap(thumbWidth, thumbHeight);  
            //从Bitmap创建一个System.Drawing.Graphics对象,用来绘制高质量的缩小图。 
            System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmp); 
            //设置 System.Drawing.Graphics对象的SmoothingMode属性为HighQuality 
            gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 
            //下面这个也设成高质量 
            gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; 
            //下面这个设成High 
            gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

 

            //把原始图像绘制成上面所设置宽高的缩小图 
            System.Drawing.Rectangle rectDestination = new System.Drawing.Rectangle(0, 0, thumbWidth, thumbHeight); 
            gr.DrawImage(image, rectDestination, 0, 0, srcWidth, srcHeight, GraphicsUnit.Pixel);


            SolidBrush drawBrush = new SolidBrush(Color.Red);

            Font drawFont = new Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Millimeter);

            int xPos = image.Height - (image.Height - 25);

            int yPos = 3;


            gr.DrawString("zydzydyzydydydyyydydy", drawFont, drawBrush, xPos, yPos);
            //保存图像,大功告成! 
            bmp.Save(dest); 
            //最后别忘了释放资源(译者PS:C#可以自动回收吧) 
            bmp.Dispose(); 
            image.Dispose(); 
           

        }

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值