国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net 圖片超過指定大小后等比例壓縮圖片的方法_.Net教程

2024-07-10 12:52:35
字體:
來源:轉載
供稿:網友

推薦:CheckBoxList兩列并排編譯為表格顯示具體實現
CheckBoxList兩列并排的顯示效果相比大家都有見到過吧,下面是具體的實現代碼,感興趣的朋友可以參考下哈

復制代碼 代碼如下:www.CuoXIn.com

/// <summary>
/// 壓縮圖片
/// </summary>
/// <returns></returns>
public string ResizePic()
{
#region 壓縮圖片開始
bool IsImgFile = true; //判斷是否為圖片文件
string filePathName = "123"; //文件存儲的路徑(文件夾名稱)
string fileName = "a.jpg"; //上傳文件的原始名稱
string fileSysName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "_" + fileName; //修改后的文件名稱
string filePath = ""; //文件路徑
string strImgPath = "/fileupload/"; //上傳路徑
if (IsImgFile)
{
int maxWidth = 600; //圖片寬度最大限制
int maxHeight = 400; //圖片高度最大限制
System.Drawing.Image imgPhoto =
System.Drawing.Image.FromFile(Server.MapPath(strImgPath) + filePathName + "/" + fileSysName);
int imgWidth = imgPhoto.Width;
int imgHeight = imgPhoto.Height;
if (imgWidth > imgHeight) //如果寬度超過高度以寬度為準來壓縮
{
if (imgWidth > maxWidth) //如果圖片寬度超過限制
{
float toImgWidth = maxWidth; //圖片壓縮后的寬度
float toImgHeight = imgHeight / (float)(imgWidth / toImgWidth); //圖片壓縮后的高度

System.Drawing.Bitmap img = new System.Drawing.Bitmap(imgPhoto,
int.Parse(toImgWidth.ToString()),
int.Parse(toImgHeight.ToString()));
string strResizePicName = Server.MapPath(strImgPath) + filePathName + "/_small_" + fileSysName;
img.Save(strResizePicName); //保存壓縮后的圖片
filePath = strImgPath + filePathName + "/_small_" + fileSysName; //返回壓縮后的圖片路徑
}
}
else
{
if (imgHeight > maxHeight)
{
float toImgHeight1 = maxHeight;
float toImgWidth1 = imgWidth / (float)(imgHeight / toImgHeight1);

System.Drawing.Bitmap img = new System.Drawing.Bitmap(imgPhoto,
int.Parse(toImgWidth1.ToString()),
int.Parse(toImgHeight1.ToString()));
string strResizePicName = Server.MapPath(strImgPath) + filePathName + "/_small_" + fileSysName;
img.Save(strResizePicName);
filePath = strImgPath + filePathName + "/_small_" + fileSysName;
}
}
}
return filePath;
#endregion
}

分享:GridView中動態設置CommandField是否可用或可見的小例子
GridView中動態設置CommandField是否可用或可見的小例子,需要的朋友可以參考一下

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 济阳县| 江华| 永丰县| 奉新县| 高州市| 太和县| 青阳县| 山东| 张掖市| 新河县| 辽阳市| 潮州市| 苏尼特右旗| 米易县| 浦北县| 龙川县| 理塘县| 湘乡市| 海晏县| 松滋市| 连江县| 湟源县| 天长市| 平凉市| 崇明县| 西丰县| 阿拉善右旗| 金湖县| 柘荣县| 台江县| 新和县| 吕梁市| 锦州市| 讷河市| 绥滨县| 定襄县| 潜江市| 亳州市| 新沂市| 东海县| 盖州市|