代码语言
.
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
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C#
】
改变图片尺寸(压缩),Image Resize
作者:
擎宇
/ 发布于
2017/2/4
/
621
/// <summary> /// Resize image with a directory as source /// </summary> /// <param name="OriginalFileLocation">Image location</param> /// <param name="heigth">new height</param> /// <param name="width">new width</param> /// <param name="keepAspectRatio">keep the aspect ratio</param> /// <param name="getCenter">return the center bit of the image</param> /// <returns>image with new dimentions</returns> public Image resizeImageFromFile(String OriginalFileLocation, int heigth, int width, Boolean keepAspectRatio, Boolean getCenter) { int newheigth = heigth; System.Drawing.Image FullsizeImage = System.Drawing.Image.FromFile(OriginalFileLocation); // Prevent using images internal thumbnail FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone); FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone); if (keepAspectRatio || getCenter) { int bmpY = 0; double resize = (double)FullsizeImage.Width / (double)width;//get the resize vector if (getCenter) { bmpY = (int)((FullsizeImage.Height - (heigth * resize)) / 2);// gives the Y value of the part that will be cut off, to show only the part in the center Rectangle section = new Rectangle(new Point(0, bmpY), new Size(FullsizeImage.Width, (int)(heigth * resize)));// create the section to cut of the original image //System.Console.WriteLine("the section that will be cut off: " + section.Size.ToString() + " the Y value is minimized by: " + bmpY); Bitmap orImg = new Bitmap((Bitmap)FullsizeImage);//for the correct effect convert image to bitmap. FullsizeImage.Dispose();//clear the original image using (Bitmap tempImg = new Bitmap(section.Width, section.Height)) { Graphics cutImg = Graphics.FromImage(tempImg);// set the file to save the new image to. cutImg.DrawImage(orImg, 0, 0, section, GraphicsUnit.Pixel);// cut the image and save it to tempImg FullsizeImage = tempImg;//save the tempImg as FullsizeImage for resizing later orImg.Dispose(); cutImg.Dispose(); return FullsizeImage.GetThumbnailImage(width, heigth, null, IntPtr.Zero); } } else newheigth = (int)(FullsizeImage.Height / resize);// set the new heigth of the current image }//return the image resized to the given heigth and width return FullsizeImage.GetThumbnailImage(width, newheigth, null, IntPtr.Zero); } /// <summary> /// Resize image with a directory as source /// </summary> /// <param name="OriginalFileLocation">Image location</param> /// <param name="heigth">new height</param> /// <param name="width">new width</param> /// <returns>image with new dimentions</returns> public Image resizeImageFromFile(String OriginalFileLocation, int heigth, int width) { return resizeImageFromFile(OriginalFileLocation, heigth, width, false, false); } /// <summary> /// Resize image with a directory as source /// </summary> /// <param name="OriginalFileLocation">Image location</param> /// <param name="heigth">new height</param> /// <param name="width">new width</param> /// <param name="keepAspectRatio">keep the aspect ratio</param> /// <returns>image with new dimentions</returns> public Image resizeImageFromFile(String OriginalFileLocation, int heigth, int width, Boolean keepAspectRatio) { return resizeImageFromFile(OriginalFileLocation, heigth, width, keepAspectRatio, false); }
试试其它关键字
同语言下
.
C#实现的html内容截取
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
.
实现对图片上传的接收
.
去除字符串中的空格,回车,换行符转变成‘;’在按‘
.
按照回车换行符分割字符串
.
文件MD5码 比较,检测文件是否一样
可能有用的
.
C#实现的html内容截取
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
.
实现对图片上传的接收
.
去除字符串中的空格,回车,换行符转变成‘;’在按‘
.
按照回车换行符分割字符串
.
文件MD5码 比较,检测文件是否一样
擎宇
贡献的其它代码
(
8
)
.
实现多字段匹配一个关键字查询语句
.
网页不满屏幕高度时,footer始终在底部显示
.
改变图片尺寸(压缩),Image Resize
.
清空指定页面上所有的控件内容
.
最大限度解决IE8兼容问题,只需要一句话
.
动态改变文字颜色和尺寸
.
poi导出word
.
显示数据碎片的SQL
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3