I would like to create dynamic images from html that I'm generating on website. I have code that generates a PSN Trophy Card, ab Xbox LIVE Gamer Card, a Steam Gamer Card, and an Xfire Gamer Card. Each card is put into its own div and built dynamically from server side code. Is there a way to capture a screenshot of a selected div on a webpage using C# and ASP.NET?
Asked
Active
Viewed 1.4k times
4
-
I suppose a solution to this would be to take a full screenshot of the page and then crop the page to the regions that include the divs that I want to grab. – Cameron Tinker Jan 30 '11 at 03:01
-
BTW, "ASP.NET" is one word - no space in between. – John Saunders Jan 30 '11 at 05:58
-
@John Saunders: While this may be true and I don't mean this comment to be rude, I don't really believe that was very necessary. It's not too important in the grand scheme of things whether there is a space or not as I've seen it written both ways. All in good humor though I suppose. – Cameron Tinker Jan 30 '11 at 07:42
-
3I think John pointed this out because it matters when a post is tagged. "ASP.NET" with no spaces is the correct way. – Jemes Jan 30 '11 at 07:46
-
Thanks for the clarification. I believe that I did tag the post with ASP.NET, but I forgot to not include a space in between the other occurrences of ASP.NET. I'll keep an eye on that in the future. I appreciate the support. – Cameron Tinker Jan 30 '11 at 07:52
-
1@pcmantinker: it wasn't necessary. It's not neccessary for me or anyone else to answer questions here, either. Yet, we do. – John Saunders Jan 30 '11 at 12:12
2 Answers
3
If you need to take a screenshot you will need to do so client side. So you will need to do so using some client side tecnology like javascript, flash, silverlight... Asp.net runs on the server so it is ruled out.
Here are some links to other related SO questions about taking a screenshot with javascript:
JavaScript code to take a screenshot of a website without using ActiveX

Community
- 1
- 1

santiagoIT
- 9,411
- 6
- 46
- 57
-
Thanks for this answer. After doing a little more research, I've decided to use GDI+ to render the various gamer cards instead of trying to take a screenshot of the html to an image. It seems like I could have an easier shot doing it that way than trying to capture the content of a given div and needing to know direct coordinates on the webpage. I appreciate your support. – Cameron Tinker Jan 30 '11 at 07:16
-
I would like to add that it's possible to take screenshots of webpages using PhantomJS. You would simply use the PhantomJS javascript API in conjunction with creating a process in C# and run the screen shot script on the command line. – Cameron Tinker Oct 31 '11 at 21:21
1
You'd need some page rendering library or service. Litmus is one such service I've heard about. You might start there.

Jason Kleban
- 20,024
- 18
- 75
- 125
-
Why the downvote? While the original question, in my opinion, was misguided in the desired approach, this is a reasonable answer as a starting place for understanding the problem. And as pcmantinker commented on another answer, he rightly concluded that a graphics library was a more straight-forward approach. – Jason Kleban Jan 30 '11 at 20:16