- //************************************************************//
- //下面給出三個簡單的方法,後面兩個方法是擴展,估計有時用得着
- //************************************************************//
- /// <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;
- }
- }
- /// <summary>
- /// 按比例縮小圖片,自動計算高度
- /// </summary>
- /// <param name="strOldPic">源圖文件名(包括路徑)</param>
- /// <param name="strNewPic">縮小後保存爲文件名(包括路徑)</param>
- /// <param name="intWidth">縮小至寬度</param>
- public void SmallPic(string strOldPic, string strNewPic, int intWidth)
- {
- System.Drawing.Bitmap objPic,objNewPic;
- try
- {
- objPic = new System.Drawing.Bitmap(strOldPic);
- int intHeight=(intWidth / objPic.Width) * objPic.Height;
- 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="intHeight">縮小至高度</param>
- public void SmallPic(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;
- }
- }
asp.net用鼠標滾輪實現圖片pdf縮放
- <mce:script language="javascript"><!--
- function bbimg(o)
- {
- var zoom=parseInt(o.style.zoom, 10)||100;
- zoom+=event.wheelDelta/12;
- if (zoom>0)
- o.style.zoom=zoom+'%';
- return false;
- }
- // --></mce:script>
- <img src='../FloorPicture/<%#DataBinder.EvalContainer.DataItem,"picture")%>'
- onload="javascript:
- if(this.width>screen.width*0.7)
- this.style.width=screen.width*0.7;"
- onmousewheel="return bbimg(this)">
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
- <title>用滾輪實現圖片縮放</title>
- </head>
- <mce:script language="JavaScript"><!--
- function zoomimg(img){
- //img.style.zoom獲取img對象的縮放比例,並轉爲十進制整數 pdf
- var zoom = parseInt(img.style.zoom,10);
- if (isNaN(zoom)){ //當zoom非數字時zoom默認爲100%
- zoom = 100;
- }
- //event.wheelDelta滾輪移動量上移+120,下移-120;顯示比例每次增減10%
- zoom += event.wheelDelta / 12;
- //當zoom大於10%時重新設置顯示比例
- if (zoom>10) img.style.zoom = zoom + "%";
- }
- // --></mce:script>
- <body>
- <br>
- <!--onmousewheel:當滾輪移動時觸發-->
- <img src="圖片路徑" mce_src="圖片路徑" onmousewheel="zoomimg(this)">
- </body>
- </html>
asp.net:pdf圖片按比例縮放,可輸入參數設定初始大小pdf
- <mce:scriptlanguage="javascript">
- <!--
- //圖片按比例縮放,可輸入參數設定初始大小
- functionresizeimg(ImgD,iwidth,iheight) {varimage=newImage();
- image.src=ImgD.src;if(image.width>0 && image.height>0){if(image.width/image.height>= iwidth/iheight){if(image.width>iwidth){
- ImgD.width=iwidth;
- ImgD.height=(image.height*iwidth)/image.width;
- }else{
- ImgD.width=image.width;
- ImgD.height=image.height;
- }
- ImgD.alt=image.width+"×"+image.height;
- }else{if(image.height>iheight){
- ImgD.height=iheight;
- ImgD.width=(image.width*iheight)/image.height;
- }else{
- ImgD.width=image.width;
- ImgD.height=image.height;
- }
- ImgD.alt=image.width+"×"+image.height;
- }
- ImgD.style.cursor="pointer";//改變鼠標指針
- ImgD.onclick =function() {window.open(ImgD.src);}//點擊打開大圖片
- if(navigator.userAgent.toLowerCase().indexOf("ie") > -1) {//判斷瀏覽器,如果是IE
- ImgD.title ="請使用鼠標滾輪縮放圖片,點擊圖片可在新窗口打開";
- ImgD.onmousewheel =functionimg_zoom()//滾輪縮放
- {
- varzoom = parseInt(this.style.zoom, 10) || 100;
- zoom +=event.wheelDelta / 12;
- if(zoom> 0) this.style.zoom = zoom +"%";
- returnfalse;
- }
- }else{//如果不是IE
- ImgD.title ="點擊圖片可在新窗口打開";
- }
- }
- }
- // -->
- </mce:script>