Take a screenshot of an iFrame

岁酱吖の 提交于 2019-12-20 02:47:11

问题


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 there know the simple and best way to achieve this?

What I am trying to do is, I am building a website that students can log in to e-government website in my country and prove if they are continuing student with a single click so that they can get discount from our service.

Edit: The puzzle should be solved in local.


回答1:


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(); 
        } 
    } 



回答2:


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.



回答3:


server side Take a screenshot of a webpage with JavaScript?

javascript http://html2canvas.hertzen.com/



来源:https://stackoverflow.com/questions/9362620/take-a-screenshot-of-an-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!