C#生成缩略图
来源:互联网 发布:乐高淘宝旗舰店 编辑:程序博客网 时间:2024/06/11 00:08
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;using System.Drawing.Imaging;namespace 生成缩略图{ class ImageClass { public bool ThumbnailCallback() { return false; } /// <summary> /// 创建缩略图方法 /// </summary> /// <param name="oldfile">原始图片路径</param> /// <param name="newfile">生成新图片路径</param> /// <param name="white">新图片宽</param> /// <param name="height">新图片高</param> /// <param name="isZoomByScale">是否按比例尺缩放</param> public void ShowThumbnail(string oldfile, string newfile, int white, int height, bool isZoomByScale) { System.Drawing.Image image = System.Drawing.Image.FromFile(oldfile); //获取原图高度和宽度 int oldh = image.Height; int oldw = image.Width; int neww, newh; neww = white; newh = height; //直接设定新图的高宽,, if (isZoomByScale) { newh = (oldh / oldw) * neww; } try { System.Drawing.Image.GetThumbnailImageAbort callb = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback); System.Drawing.Image bt = new System.Drawing.Bitmap(neww, newh); System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bt); gr.Clear(Color.White); gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; gr.DrawImage(image, new Rectangle(0, 0, neww, newh), 0, 0, oldw, oldh, GraphicsUnit.Pixel); switch (oldfile.Substring(oldfile.Length - 3).ToUpper()) { case "JPG": bt.Save(newfile, ImageFormat.Jpeg); break; case "GIF": bt.Save(newfile, ImageFormat.Gif); break; case "PNG": bt.Save(newfile, ImageFormat.Png); break; default: bt.Save(newfile, ImageFormat.Jpeg); break; } gr.Dispose(); bt.Dispose(); image.Dispose(); } catch { } } }}
阅读全文
0 0
- c#生成缩略图
- c#生成缩略图
- c#生成缩略图
- c#生成缩略图
- C#生成缩略图
- C#生成缩略图代码
- 关于生成缩略图:c#
- c#生成缩略图
- c#生成缩略图
- c# 生成缩略图
- c#生成缩略图
- c#生成缩略图
- C#生成缩略图代码
- c# 生成缩略图
- c# 生成缩略图
- C#自动生成缩略图
- C#生成缩略图
- C# 生成缩略图
- Python批量修改Excel文件格式:加粗、颜色交替、渐变背景色填充
- Java File RenameTo函数返回false及正确写法
- java当中的日历
- 20171010
- redis主从复制和集群实现原理
- C#生成缩略图
- 1067. 试密码(字符串)
- 寄存器、存储器、内存的区别
- 关于Java虚拟机
- 如何解决ajax跨域问题(转)
- javaweb之国际化
- LeetCode 题型归类
- 【API性能】3、多机jmeter压力测试搭建
- 基于TI-RTOS的CC2640 UART