足球游戏_中国足彩网¥体育资讯$

asp.net 生成缩略图的实例源代码
来源:易贤网 阅读:550 次 日期:2014-10-27 14:19:06
温馨提示:易贤网小编为您整理了“asp.net 生成缩略图的实例源代码”,方便广大网友查阅!

using system;

using system.data;

using system.configuration;

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;

using system.drawing.imaging;

///

/// 图片处理类

/// 1、生成缩略图片或按照比例改变图片的大小和画质

/// 2、将生成的缩略图放到指定的目录下

///

public class imageclass

{

public system.drawing.image resourceimage;

private int imagewidth;

private int imageheight;

public string errmessage;

///

/// 类的构造函数

///

/// 图片文件的全路径名称

public imageclass(string imagefilename)

{

resourceimage = system.drawing.image.fromfile(imagefilename);

errmessage = ;

}

public bool thumbnailcallback()

{

return false;

}

///

/// 生成缩略图重载方法1,返回缩略图的image对象

///

/// 缩略图的宽度

/// 缩略图的高度

/// 缩略图的image对象

public system.drawing.image getreducedimage(int width, int height)

{

try

{

system.drawing.image reducedimage;

system.drawing.image.getthumbnailimageabort callb = new system.drawing.image.getthumbnailimageabort(thumbnailcallback);

reducedimage = resourceimage.getthumbnailimage(width, height, callb, intptr.zero);

return reducedimage;

}

catch (exception e)

{

errmessage = e.message;

return null;

}

}

///

/// 生成缩略图重载方法2,将缩略图文件保存到指定的路径

///

/// 缩略图的宽度

/// 缩略图的高度

/// 缩略图保存的全文件名,(带路径),参数格式:d:images ilename.jpg

/// 成功返回true,否则返回false

public bool getreducedimage(int width, int height, string targetfilepath)

{

try

{

system.drawing.image reducedimage;

system.drawing.image.getthumbnailimageabort callb = new system.drawing.image.getthumbnailimageabort(thumbnailcallback);

reducedimage = resourceimage.getthumbnailimage(width, height, callb, intptr.zero);

reducedimage.save(@targetfilepath, imageformat.jpeg);

reducedimage.dispose();

return true;

}

catch (exception e)

{

errmessage = e.message;

return false;

}

}

///

/// 生成缩略图重载方法3,返回缩略图的image对象

///

/// 缩略图的宽度百分比 如:需要百分之80,就填0.8

/// 缩略图的image对象

public system.drawing.image getreducedimage(double percent)

{

try

{

system.drawing.image reducedimage;

system.drawing.image.getthumbnailimageabort callb = new system.drawing.image.getthumbnailimageabort(thumbnailcallback);

imagewidth = convert.toint32(resourceimage.width * percent);

imageheight = convert.toint32(resourceimage.width * percent);

reducedimage = resourceimage.getthumbnailimage(imagewidth, imageheight, callb, intptr.zero);

return reducedimage;

}

catch (exception e)

{

errmessage = e.message;

return null;

}

}

///

/// 生成缩略图重载方法4,返回缩略图的image对象

///

/// 缩略图的宽度百分比 如:需要百分之80,就填0.8

/// 缩略图保存的全文件名,(带路径),参数格式:d:images ilename.jpg

/// 成功返回true,否则返回false

public bool getreducedimage(double percent, string targetfilepath)

{

try

{

system.drawing.image reducedimage;

system.drawing.image.getthumbnailimageabort callb = new system.drawing.image.getthumbnailimageabort(thumbnailcallback);

imagewidth = convert.toint32(resourceimage.width * percent);

imageheight = convert.toint32(resourceimage.width * percent);

reducedimage = resourceimage.getthumbnailimage(imagewidth, imageheight, callb, intptr.zero);

reducedimage.save(@targetfilepath, imageformat.jpeg);

reducedimage.dispose();

return true;

}

catch (exception e)

{

errmessage = e.message;

return false;

}

}

}

中国足彩网信息请查看IT技术专栏

中国足彩网信息请查看网络编程
易贤网手机网站地址:asp.net 生成缩略图的实例源代码
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 足球游戏_中国足彩网¥体育资讯$ 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:易贤网
云南网警报警专用图标