Take a screenshot of an iFrame

前端 未结 3 1498
说谎
说谎 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:17

    Unless I'm misunderstanding you, this is impossible.

    • You cannot instruct the user's browser to take a screenshot (this would be a security risk … and has few uses cases anyway).
    • You cannot load the page you want a screenshot of yourself (with server side code) because you don't have the credentials needed to access it.
    0 讨论(0)
  • 2021-01-19 03:28

    server side Take a screenshot of a webpage with JavaScript?

    javascript http://html2canvas.hertzen.com/

    0 讨论(0)
  • 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(); 
            } 
        } 
    
    0 讨论(0)
提交回复
热议问题