Take a screenshot of an iFrame

前端 未结 3 1497
说谎
说谎 2021-01-19 03:05

I am looking for a simple way to take a screenshot of an iFrame in my ASP page. I just couldn\'t achieve it with C# and I lack of knowledge of Javascript! Does anyone out th

3条回答
  •  隐瞒了意图╮
    2021-01-19 03:33

    this piece of code worked for me. I hope it does the same to the others.

    private void saveURLToImage(string url) 
        { 
            if (!string.IsNullOrEmpty(url)) 
            { 
                string content = ""; 
    
    
                System.Net.WebRequest webRequest = WebRequest.Create(url); 
                System.Net.WebResponse webResponse = webRequest.GetResponse(); 
                System.IO.StreamReader sr = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8"));
    
                content = sr.ReadToEnd(); 
                //save to file 
                byte[] b = Convert.FromBase64String(content); 
                System.IO.MemoryStream ms = new System.IO.MemoryStream(b); 
                System.Drawing.Image img = System.Drawing.Image.FromStream(ms); 
                img.Save(@"c:\pic.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); 
    
    
                img.Dispose(); 
                ms.Close(); 
            } 
        } 
    

提交回复
热议问题