2011-01-26 9 views
1

내가하려는 것은 현재 브라우저 너비/높이를 기반으로 이미지의 너비/높이의 크기를 조정하여 이미지 소스를 업데이트하는 것입니다. 모든 것이 로컬에서 훌륭하게 작동하지만 내 환경 외부에서 이미지가 업데이트되지 않습니다.Response.OutputStream을 통한 Jquery img src 업데이트

도움말/정보를 제공해 주시면 감사하겠습니다.

이미지

<img class='image' src='./ImageResize.aspx?image=http://img.dailymail.co.uk/i/pix/2008/04_02/alligatorL_468x343.jpg' /> 

JQuery와 SRC 조작

//Adds resize image demensions 

    $('image').each(function() { 

     var sSource = $(this).attr('src'); 
     sSource = sSource + "&width=" + $(window).width + "&height=" + 
        $(window).height(); 
     $(this).attr('src', sSource); 
    }); 

Asp.net 코드

protected void ImageWork() 
{ 
    var sPath = ""; 
    var sWidth = 0; 
    var sHeight = 0; 

    if (Request["image"] != null) 
    { 
     sPath = Request["image"].ToString(); 
    } 
    if (Request["width"] != null & Request["height"] != null) 
    { 
     sWidth = Convert.ToInt32(Request["width"]); 
     sHeight = Convert.ToInt32(Request["height"]); 
    } 

    if (!string.IsNullOrEmpty(sPath) & (sWidth > 0) & (sHeight > 0)) 
    { 

     if (sPath.Contains("http")) 
     { 

      MemoryStream xPath; 
      WebClient wc = new WebClient(); 
      byte[] originalData = wc.DownloadData(sPath); 

      xPath = new MemoryStream(originalData); 

      using (Bitmap image = new Bitmap(xPath)) 
      { 
       int xWidth = image.Width; 
       int xHeight = image.Height; 

       if ((xWidth < sWidth) & (xHeight < sHeight)) 
       { 
        Response.ContentType = "image/Jpeg"; 
        image.Save(Response.OutputStream, ImageFormat.Jpeg); 
       } 
       else 
       { 
        xWidth = (int)Math.Floor(((double)image.Width * ((double)sWidth/(double)image.Width))); 
        xHeight = (int)Math.Floor((double)image.Height * ((double)sHeight/(double)image.Height)); 

        using (Bitmap newImage = new Bitmap(image, xWidth, xHeight)) 
        { 
         Response.ContentType = "image/Jpeg"; 
         newImage.Save(Response.OutputStream, ImageFormat.Jpeg); 
        } 
       } 
      } 
     } 
     else 
     { 
      var xPath = sPath; 
      using (Bitmap image = new Bitmap(xPath)) 
      { 
       int xWidth = image.Width; 
       int xHeight = image.Height; 

       if ((xWidth < sWidth) & (xHeight < sHeight)) 
       { 
        Response.ContentType = "image/Jpeg"; 
        image.Save(Response.OutputStream, ImageFormat.Jpeg); 
       } 
       else 
       { 
        xWidth = (int)Math.Floor(((double)image.Width * ((double)sWidth/(double)image.Width))); 
        xHeight = (int)Math.Floor((double)image.Height * ((double)sHeight/(double)image.Height)); 

        using (Bitmap newImage = new Bitmap(image, xWidth, xHeight)) 
        { 
         Response.ContentType = "image/Jpeg"; 
         newImage.Save(Response.OutputStream, ImageFormat.Jpeg); 
        } 
       } 
      } 
     } 

    } 
} 
+0

브라우저에 오류가 있습니까? – TheGeekYouNeed

답변

2

뒤에 난 전문가는 아니지만, 난 JS 코드의 첫 번째 라인은해야한다고 생각 말 :

$('.image').each(function() ... 

"이미지"앞에 점 (.)이 있음에 유의하십시오.