Capture Screenshots in C#


/ Published in: C#
Save to your folder(s)

Capture Web Screenshots easily with the [GrabzIt C# API](http://grabz.it/api/aspnet/).

This handy code snippet will fire a event when your screenshot is ready so that your code can process the screenshot anyway you wish!

You will need the free [GrabzIt Code Library](http://grabz.it/api/aspnet/download.aspx) to get started.

The code snippet assumes it is located within a ASPX page, in this example we are taking a screenshot of google.com.


Copy this code and paste it in your HTML
  1. /*
  2. * The ASPX code behind
  3. */
  4.  
  5. //Replace "APPLICATION KEY", "APPLICATION SECRET" with the values from your account!
  6. private GrabzItClient grabzIt = GrabzItClient.Create("APPLICATION KEY", "APPLICATION SECRET");
  7.  
  8. protected override void OnLoad(EventArgs e)
  9. {
  10. grabzIt.ScreenShotComplete += grabzIt_ScreenShotComplete;
  11. grabzIt.TakePicture("http://www.google.com", HttpContext.Current.Request.Url.Scheme + "://" +
  12. HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath
  13. + "GrabzIt.ashx");
  14. }
  15.  
  16. //The event method saves the screenshot
  17. protected void grabzIt_ScreenShotComplete(object sender, ScreenShotEventArgs result)
  18. {
  19. Image image = GrabzItClient.GetPicture(result.ID);
  20. image.Save(Server.MapPath("~/screenshots/"+result.Filename));
  21. }
  22.  
  23. /*
  24. *Add the following lines to your web.config. This allows the screenshot event to work
  25. */
  26.  
  27. <httpHandlers>
  28. <add verb="*" path="GrabzIt.ashx" type="GrabzIt.Handler, GrabzIt" />
  29. </httpHandlers>

URL: http://grabz.it/api/aspnet/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.