2010-07-28 6 views

답변

1

시도해보십시오. SnapCasa의 무료 서비스를 사용해보십시오. 다음과 같이 이미지 태그를 구성하면됩니다.

<img src="http://SnapCasa.com/Get.aspx?code=[code]&size=[size]&url=[url]" /> 

가입이 필요하지만 한 달에 50 만 건의 요청은 무료입니다. [코드]는 가입 후 제공하는 API입니다. [크기]는 3 가지 크기 중 하나입니다. [url]은 미리보기 이미지를 표시 할 사이트의 웹 사이트 주소입니다. 당신은 당신의 코드에서 이미지 작업 할 경우

가 여기 헬퍼 메소드의 커플 : 다음

static public byte[] GetBytesFromUrl(string url) 
{ 
    byte[] b; 
    HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url); 
    WebResponse myResp = myReq.GetResponse(); 

    Stream stream = myResp.GetResponseStream(); 
    //int i; 
    using (BinaryReader br = new BinaryReader(stream)) 
    { 
     //i = (int)(stream.Length); 
     b = br.ReadBytes(500000); 
     br.Close(); 
    } 
    myResp.Close(); 
    return b; 
} 

static public void WriteBytesToFile(string fileName, byte[] content) 
{ 
    FileStream fs = new FileStream(fileName, FileMode.Create); 
    BinaryWriter w = new BinaryWriter(fs); 
    try 
    { 
     w.Write(content); 
    } 
    finally 
    { 
     fs.Close(); 
     w.Close(); 
    } 
} 

, 코드에서 바로 사용

//get byte array for image 
var imageBytes = GetBytesFromUrl("http://SnapCasa.com/Get.aspx?code=[code]&size=[size]&url=[url]"); 
//save file to disk 
WriteBytesToFile("c:\someImageFile.jpg", imageBytes); 
0

것은 행할 수 있어야 웹 브라우저 개체를 사용하고 뷰포트를 축소판 크기로 조정 된 비트 맵에 저장합니다.

이 코드를 테스트하지는 않았지만 미리보기 매개 변수 대신 사용하여 조정 해보십시오.

using (WebBrowser wb = new WebBrowser()) { 
    wb.ScrollBarsEnabled = false; 
    wb.AllowNavigation = true; 
    wb.ScriptErrorsSuppressed = true; 
    wb.ClientSize = new Size(thumbInfo_viewportWidth, thumbInfo_viewportHeight); 

    if ((thumbInfo_Uri != null)) { 
     wb.Navigate(thumbInfo_Uri.AbsoluteUri); 
    } else { 
     wb.Navigate("about:blank"); 
     HtmlDocument doc = wb.Document.OpenNew(true); 
     doc.Write(thumbInfo_HTML); 
     wb.Refresh(WebBrowserRefreshOption.Completely); 
    } 

    // create an image of the client area of the webbrowser control, than 
    // scale it down to the dimensions specified. 
    if ((wb.Document != null && wb.Document.Body != null)) { 
     Rectangle rec = default(Rectangle); 
     rec.Size = wb.ClientSize; 
     using (Bitmap fullSizeBitmap = new Bitmap(thumbInfo_viewportWidth, thumbInfo_viewportHeight)) { 
      wb.DrawToBitmap(fullSizeBitmap, wb.Bounds); 
      using (Bitmap scaledBitmap = new Bitmap(thumbInfo_width, thumbInfo_height)) { 
       using (Graphics gr = Graphics.FromImage(scaledBitmap)) { 
        gr.SmoothingMode = Drawing2D.SmoothingMode.HighQuality; 
        gr.CompositingQuality = Drawing2D.CompositingQuality.HighQuality; 
        gr.InterpolationMode = Drawing2D.InterpolationMode.High; 
        Rectangle rect = new Rectangle(0, 0, thumbInfo_width, thumbInfo_height); 
        gr.DrawImage(fullSizeBitmap, rect, 0, 0, rec.Size.Width, rec.Size.Height, GraphicsUnit.Pixel); 

        scaledBitmap.Save(thumbInfo_physicalPath); 
       } 
      } 
     } 
    } 
} 

비싼 프로세스라는 것을주의해야 할 한 가지.

관련 문제