2012-10-09 4 views
0

FileUpload 대화 상자를 사용하여 이미지를 업로드하려고 할 때 행운이 없다. 가로 세로 비율을 유지하면서 크기를 조정 한 다음 C# 및 ASP.NET을 사용하여 파일 시스템에 저장합니다. 누구나 작동하는 솔루션 또는 링크가 있습니까? 나에게 실용적인 예를 보여 줄 수있는 곳으로? 내가 보니 시도한 솔루션의 많은는 C#을 작동하지만 ASP.NETASP.NET 이미지 업로드, 크기 조정 및 파일 시스템에 저장.

+0

내가 당신 VB에게 제공 할 수 있습니다 내 ASP.NET 서버에서 실행되는 .NET 버전. 변환 할 수 있습니까? –

+1

왜 ASP.NET 프로젝트에 외부 DLL로 C# 코드를 사용하지 않습니까? 그냥 필요한 기능을 호출 ... – Mortalus

+0

당신은 제게 VB 버전을 보내 주시겠습니까. 나는 그것을 줄 것이다. – Pacobart

답변

0

ImageResizer 당신이 원하는 모든 것을 줄 것이다 :

http://imageresizing.net/

string fileExt = System.IO.Path.GetExtension(imageUpload.FileName); 
if (string.Equals(fileExt, ".jpg", StringComparison.OrdinalIgnoreCase)) 
{ 
    foreach (string fileKey in HttpContext.Current.Request.Files.Keys) 
    { 
     HttpPostedFile file = HttpContext.Current.Request.Files[fileKey]; 
     if (file.ContentLength <= 0) continue; //Skip unused file controls. 

     try 
     { 
      ImageJob i = new ImageJob(file, "~/eventimages/<guid>_<filename:A-Za-z0-9>.<ext>", 
       new ResizeSettings("width=60&height=60&format=jpg&crop=auto")); 
      i.Build(); 

      ImageJob j = new ImageJob(file, "~/eventimages/<guid>_<filename:A-Za-z0-9>.<ext>", 
       new ResizeSettings("width=250&height=250&format=jpg&crop=auto")); 
      j.Build(); 

      string sitePath = MapPath(@"~"); 
      thumbImagePath = i.FinalPath.Replace(sitePath, "~\\"); 
      mainImagePath = j.FinalPath.Replace(sitePath, "~\\"); 
     } 
     catch 
     { 
    // Had to swallow the exception here: 
    // http://stackoverflow.com/questions/7533845/system-argumentexception-parameter-is-not-valid 
     } 
    } 
    } 
관련 문제