控製圖片按比例顯示[FREETEXTBOX](2)

來源:互聯網
上載者:User

此方法用於在FREETEXTBOX中的上傳圖片:(參照上傳圖片)

if (UploadFile.PostedFile.FileName.Trim() != "")
{
if (IsValidFileType(UploadFile.PostedFile.FileName))
{
try
{
string UploadFileName = "";
string UploadFileDestination = "";
string filename= "";
int ppp = 0;
        
filename=(DateTime.Now.ToString()).Replace(":","");
filename= filename.Replace(" ","");
filename= filename.Replace("-","");
    
UploadFileName = UploadFile.PostedFile.FileName;
ppp=UploadFileName.LastIndexOf(".");
UploadFileName=UploadFileName.Substring(ppp,UploadFileName.Length-ppp);
filename = filename+UploadFileName;        
        
        
UploadFileDestination = HttpContext.Current.Request.PhysicalApplicationPath;
UploadFileDestination += CurrentImagesFolder.Value;
UploadFileDestination += "//";
UploadFile.PostedFile.SaveAs(UploadFileDestination + filename); 
        
string urrl = Server.MapPath("../images/") + filename;
double width=0;
double height=0;
System.Drawing.Bitmap  imgObj = new Bitmap(urrl);
width=imgObj.Width;        
height=imgObj.Height;
        
double k;//金儒 2005.5.11
if ((width != 0) && (height != 0))
{          
k=Convert.ToDouble( width/height); 
          
if(k>=1)
{
if (width>=750)
{
width=750;
height=width/k;
}
}
else
{
if (height>=750)
{
height=750;
width=k*height;
}
}
}
        
string imgurl = @"../AspNetForums/images/" + filename;
this.iw.Value = width.ToString();
this.ih.Value = height.ToString();
this.ip.Value = imgurl;           
ResultsMessage.Text = UploadSuccessMessage;
}
catch
{
ResultsMessage.Text = UploadFailureMessage;
}
}
else
{
ResultsMessage.Text = InvalidFileTypeMessage;
}
}

其中的width ,height 用於傳回值,用來在編輯框裡顯示大小。

function returnImage(imagename,width,height) { var imgAr = new Array(); imgAr["filename"] = imagename; imgAr["width"] = width; imgAr["height"] = height; window.parent.returnValue = imgAr; window.parent.close(); }

(首先width ,height分別付給this.form.elements['ip'].value,this.form.elements['iw'].value,this.form.elements['ih'].value  然後“確定”傳到接收的頁面)

<INPUT id="enter" onclick="returnImage(this.form.elements['ip'].value,this.form.elements['iw'].value,this.form.elements['ih'].value);"
           type="button" value=" 確定 ">

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.