Posted By

Maximus1983 on 05/18/12


Tagged

library screen screenshots grab


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

configuration
Priestd09


Capture Screenshots in C#


 / Published in: C#
 

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

Capture Web Screenshots easily with the GrabzIt C# API.

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 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.

  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>

Report this snippet  

You need to login to post a comment.