本文實(shí)例主要展示了.Net實(shí)現(xiàn)上傳圖片按比例自動(dòng)縮小或放大的方法,是非常實(shí)用的功能。分享給大家供大家參考之用。具體方法如下:
//// <summary>/// 按比例縮小圖片,自動(dòng)計(jì)算寬度/// </summary>/// <param name="strOldPic">源圖文件名(包括路徑)</param>/// <param name="strNewPic">縮小后保存為文件名(包括路徑)</param>/// <param name="intHeight">縮小至高度</param>public void SmallPicWidth(string strOldPic, string strNewPic, int intHeight){ System.Drawing.Bitmap objPic, objNewPic; try { objPic = new System.Drawing.Bitmap(strOldPic); int intWidth = (intHeight / objPic.Height) * objPic.Width; objNewPic = new System.Drawing.Bitmap(objPic, intWidth, intHeight); objNewPic.Save(strNewPic); } catch (Exception exp) { throw exp; } finally { objPic = null; objNewPic = null; }}/**//// <summary>/// 縮小圖片/// </summary>/// <param name="strOldPic">源圖文件名(包括路徑)</param>/// <param name="strNewPic">縮小后保存為文件名(包括路徑)</param>/// <param name="intWidth">縮小至寬度</param>/// <param name="intHeight">縮小至高度</param>public void SmallPic(string strOldPic, string strNewPic, int intWidth, int intHeight){ System.Drawing.Bitmap objPic, objNewPic; try { objPic = new System.Drawing.Bitmap(strOldPic); objNewPic = new System.Drawing.Bitmap(objPic, intWidth, intHeight); objNewPic.Save(strNewPic); } catch (Exception exp) { throw exp; } finally { objPic = null; objNewPic = null; }}
希望本文所述實(shí)例對(duì)大家的asp.net程序設(shè)計(jì)有一定的借鑒價(jià)值。
|
新聞熱點(diǎn)
疑難解答
圖片精選