图片缩略图
来源:互联网 发布:查看linux系统多少位 编辑:程序博客网 时间:2024/04/28 22:56
public void SmallPic(string strOldPic, string strNewPic, int intWidth,int intHeight,bool deletl)
{
System.Drawing.Bitmap objPic, objNewPic;
objPic = new System.Drawing.Bitmap(strOldPic);
int newwidth= ResizeImage(objPic.Width, objPic.Height, intWidth, intHeight);
int newheight = ResizeImagehig(objPic.Width, objPic.Height, intWidth, intHeight);
objNewPic = new System.Drawing.Bitmap(objPic, newwidth, newheight);
objNewPic.Save(strNewPic);
objPic.Dispose();
objNewPic.Dispose();
objPic = null;
objNewPic = null;
if (deletl == true)
{
File.Delete(strOldPic);
}
}
/**/
/// <summary>
/// 计算新宽度
/// </summary>
/// <param name="width">原始宽度</param>
/// <param name="height">原始高度</param>
/// <param name="maxWidth">最大新宽度</param>
/// <param name="maxHeight">最大新高度</param>
/// <returns></returns>
private int ResizeImage(int width, int height, int maxWidth, int maxHeight)
{
decimal MAX_WIDTH = (decimal)maxWidth;
decimal MAX_HEIGHT = (decimal)maxHeight;
decimal ASPECT_RATIO = MAX_WIDTH / MAX_HEIGHT;
int newWidth, newHeight;
decimal originalWidth = (decimal)width;
decimal originalHeight = (decimal)height;
if (originalWidth > MAX_WIDTH || originalHeight > MAX_HEIGHT)
{
decimal factor;
// determine the largest factor
if (originalWidth / originalHeight > ASPECT_RATIO)
{
factor = originalWidth / MAX_WIDTH;
newWidth = Convert.ToInt32(originalWidth / factor);
newHeight = Convert.ToInt32(originalHeight / factor);
}
else
{
factor = originalHeight / MAX_HEIGHT;
newWidth = Convert.ToInt32(originalWidth / factor);
newHeight = Convert.ToInt32(originalHeight / factor);
}
}
else
{
newWidth = width;
newHeight = height;
}
return newWidth;
}
private int ResizeImagehig(int width, int height, int maxWidth, int maxHeight)
{
decimal MAX_WIDTH = (decimal)maxWidth;
decimal MAX_HEIGHT = (decimal)maxHeight;
decimal ASPECT_RATIO = MAX_WIDTH / MAX_HEIGHT;
int newWidth, newHeight;
decimal originalWidth = (decimal)width;
decimal originalHeight = (decimal)height;
if (originalWidth > MAX_WIDTH || originalHeight > MAX_HEIGHT)
{
decimal factor;
// determine the largest factor
if (originalWidth / originalHeight > ASPECT_RATIO)
{
factor = originalWidth / MAX_WIDTH;
newWidth = Convert.ToInt32(originalWidth / factor);
newHeight = Convert.ToInt32(originalHeight / factor);
}
else
{
factor = originalHeight / MAX_HEIGHT;
newWidth = Convert.ToInt32(originalWidth / factor);
newHeight = Convert.ToInt32(originalHeight / factor);
}
}
else
{
newWidth = width;
newHeight = height;
}
return newHeight;
}
- 图片缩略图
- 图片缩略图
- 图片缩略图
- 图片缩略图
- 生成图片缩略图
- 生成图片缩略图
- 上传图片生成缩略图
- PHP生成图片缩略图
- 上传图片生成缩略图
- PHP生成图片缩略图
- 上传图片生成缩略图
- 上传图片生成缩略图
- j2me 图片缩略图
- 上传图片生成缩略图
- 生成图片缩略图
- PHP图片生成缩略图
- 图片生成缩略图类
- PHP生成图片缩略图
- Ruby on Rails的下载及安装以及开发环境的搭建
- 使用带谓语的XPath进行结果过滤
- 按日期查询数量的SQL
- 论“废话”的语用功能
- oracle行列转换总结
- 图片缩略图
- OGRE分析之文件系统(一)
- 防止程序执行过程中Windows休眠
- 记笔记
- OGRE分析之文件系统(二)
- C语言学习零碎整理(3):sprintf函数
- OGRE分析之文件系统(三)
- Todosit and Joesgoals
- OGRE分析之文件系统(四)