代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
C#生成缩略图源码
作者:
Dezai.CN
/ 发布于
2012/10/25
/
670
<div>//<span style="color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px; background-color: rgb(250, 247, 239);">先看调用的方法</span></div> <div> <div>using System;</div> <div>using System.Data;</div> <div>using System.Configuration;</div> <div>using System.Collections;</div> <div>using System.Web;</div> <div>using System.Web.Security;</div> <div>using System.Web.UI;</div> <div>using System.Web.UI.WebControls;</div> <div>using System.Web.UI.WebControls.WebParts;</div> <div>using System.Web.UI.HtmlControls;</div> <div></div> <div>public partial class test_Default : System.Web.UI.Page</div> <div>{</div> <div> protected void Page_Load(object sender, EventArgs e)</div> <div> {</div> <div> generalImage();</div> <div> } <div> private void generalImage()</div> <div> {</div> <div> string savePath = @"images/123.jpg";//原图路径</div> <div> string smallPath = @"images/small/123.jpg";//要生成的小图</div> <div> savePath = Server.MapPath(savePath);//这一步别忘了。</div> <div> smallPath = Server.MapPath(smallPath);//同样这里也不要忘了。</div> <div> YD.Common.ImageClass imageClass = new YD.Common.ImageClass();</div> <div> imageClass.ShowThumbnail(savePath, smallPath, 200, 153);//这样调用</div> <div> } <div>} <div><span style="color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px; background-color: rgb(250, 247, 239);">生成小图的类:</span></div> <div> <div>using System;</div> <div>using System.Data;</div> <div>using System.Configuration;</div> <div>using System.Web;</div> <div>using System.Web.Security;</div> <div>using System.Web.UI;</div> <div>using System.Web.UI.WebControls;</div> <div>using System.Web.UI.WebControls.WebParts;</div> <div>using System.Web.UI.HtmlControls;</div> <div>using System.Drawing;</div> <div>using System.Drawing.Imaging;</div> <div>using System.IO;</div> <div>/// <summary></div> <div>/// ImageClass 的摘要说明</div> <div>/// </summary></div> <div>namespace YD.Common</div> <div>{</div> <div> public class ImageClass</div> <div> {</div> <div> public bool ThumbnailCallback()</div> <div> {</div> <div> return false;</div> <div> } <div> public void ShowThumbnail(string oldfile, string newfile, int white, int height)</div> <div> {</div> <div> System.Drawing.Image image = System.Drawing.Image.FromFile(oldfile);</div> <div> //获取原图高度和宽度</div> <div> int oldh = image.Height;</div> <div> int oldw = image.Width;</div> <div> int neww, newh;</div> <div> neww = white; newh = height; //直接设定新图的高宽,,</div> <div></div> <div> try</div> <div> {</div> <div> System.Drawing.Image.GetThumbnailImageAbort callb = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);</div> <div> System.Drawing.Image bt = new System.Drawing.Bitmap(neww, newh);</div> <div> System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bt);</div> <div> gr.Clear(Color.White);</div> <div> gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;</div> <div> gr.DrawImage(image, new Rectangle(0, 0, neww, newh), 0, 0, oldw, oldh, GraphicsUnit.Pixel);</div> <div> switch (oldfile.Substring(oldfile.Length - 3).ToUpper())</div> <div> {</div> <div> case "JPG":</div> <div> bt.Save(newfile, ImageFormat.Jpeg);</div> <div> break;</div> <div> case "GIF":</div> <div> bt.Save(newfile, ImageFormat.Gif);</div> <div> break;</div> <div> case "PNG":</div> <div> bt.Save(newfile, ImageFormat.Png);</div> <div> break;</div> <div> default:</div> <div> bt.Save(newfile, ImageFormat.Jpeg);</div> <div> break;</div> <div> } <div> gr.Dispose();</div> <div> bt.Dispose();</div> <div> image.Dispose();</div> <div> } <div> catch { } <div></div> <div> } <div> } <div>} <div></div> </div> </div>
试试其它关键字
缩略图源码
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3