中成网站建设
    成都做网站,就选中成网站建设!专业四川网站建设,成都网站建设服务提供商
            企业宣传网站建设、电子商务网站建设、OA办公系统。联系电话:028-66165255
    资讯列表  
 ASP.NET防止用户多次登录的方法…
 生成不重复的随机整数
 ASP.NET获取IP的6种方法
 ASP dot net 里的状态管理-Ses…
 判断获取的参数是否为null
 中文验证码生成实例
 微软发布第二个实验版的.Net 4…
 微软轻量级Web开发平台WebMatr…
 asp.net 生成图片验证码
 Asp.net直接保存文件到客户端
 .Net开发中的多线程编程总结
 C#中关于get和set的详细例子介…
 ASP.NET编程技巧:提高asp.net…
 asp.net 剪切 缩小图片原码
 截断过长字符串为省略号算法
    资讯详情  
asp.net 剪切 缩小图片原码
发布时间:2010-06-27                  来源:成都网站建设--中成网建         【加入收藏】

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;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Drawing.Imaging;
using System.Drawing;

public partial class Default2 : System.Web.UI.Page
{
    public void ImgReduceCutOut(int int_Width, int int_Height, string input_ImgUrl, string out_ImgUrl)
    {
        // ===上传标准图大小===
        int int_Standard_Width = 160;
        int int_Standard_Height = 160;

        int Reduce_Width = 0; // 缩小的宽度
        int Reduce_Height = 0; // 缩小的高度
        int CutOut_Width = 0; // 裁剪的宽度
        int CutOut_Height = 0; // 裁剪的高度
        int level = 100; //缩略图的质量 1-100的范围

        // ===获得缩小,裁剪大小===
        if (int_Standard_Height * int_Width / int_Standard_Width > int_Height)
        {
            Reduce_Width = int_Width;
            Reduce_Height = int_Standard_Height * int_Width / int_Standard_Width;
            CutOut_Width = int_Width;
            CutOut_Height = int_Height;
        }
        else if (int_Standard_Height * int_Width / int_Standard_Width < int_Height)
        {
            Reduce_Width = int_Standard_Width * int_Height / int_Standard_Height;
            Reduce_Height = int_Height;
            CutOut_Width = int_Width;
            CutOut_Height = int_Height;
        }
        else
        {
            Reduce_Width = int_Width;
            Reduce_Height = int_Height;
            CutOut_Width = int_Width;
            CutOut_Height = int_Height;
        }

        // ===通过连接创建Image对象===
        System.Drawing.Image oldimage = System.Drawing.Image.FromFile(Server.MapPath(input_ImgUrl));

        //// ===缩小图片===
        //System.Drawing.Image thumbnailImage = oldimage.GetThumbnailImage(Reduce_Width, Reduce_Height, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
        //Bitmap bm = new Bitmap(thumbnailImage);
        Bitmap bm = new Bitmap(oldimage);
        // ===处理JPG质量的函数===
        ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
        ImageCodecInfo ici = null;
        foreach (ImageCodecInfo codec in codecs)
        {
            if (codec.MimeType == "image/jpeg")
                ici = codec;
        }
        EncoderParameters ep = new EncoderParameters();
        ep.Param[0] = new EncoderParameter(Encoder.Quality, (long)level);

        bm.Save(Server.MapPath("2.jpg"), ici, ep);

        // ===裁剪图片===
        Rectangle cloneRect = new Rectangle(70, 0, CutOut_Width, CutOut_Height);
        PixelFormat format = bm.PixelFormat;
        Bitmap cloneBitmap = bm.Clone(cloneRect, format);

        // ===保存图片===
        cloneBitmap.Save(Server.MapPath(out_ImgUrl), ici, ep);
    }
    public bool ThumbnailCallback()
    {
        return false;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
           // ImgReduceCutOut(397, 319, "face.jpg", "2.jpg");

        }
    }
}

 

 
上一篇:sqlserver中如何实现时间按月,日,小时分组查询
下一篇:在asp.net中备份还原SQL_Server数据库
【打印】    【关闭】    【字体变小】    【字体变大】

友情链接

首页  |  建站学院  |  网站建设  |  成功案例  |  业务体系  |  软件定制  |  解决方案  |  联系我们  |  免责声明
中成网建公司地址:四川省成都市双楠双安东巷1号18-3-5 电话:028-6616 5255 版权所有 @ 中成网建
成都网站建设网址:www.csccd.net www.csccd.cn 邮箱:web#csccd.net
信息产业部备案号:蜀ICP备08106559号