1

Does anyone know of any tools where you can take the content of an HTML control (presuambly div) and export it to one of a few various image formats (jpg, png and bmp would suffice)? I'd prefer the rendering to be done server-side (GDI is fine) and just create an image I can return with an HttpHandler so it doesn't need saved if at all possible. I know a number of reporting tools (SSRS, Telerik Reporting) offer export to image options, but I can't figure out how they do this.

Scott Salyer
  • 2,165
  • 7
  • 45
  • 82

2 Answers2

2

You can spin up IE or some other browser on your server side and use GDI to take a screenshot of that window, but pinpointing a specific div will take more work.

If you need client-side screenshots, you'll need to use Java or something similar.

How to take screenshot of div from a webpage using C# and ASP.NET?

may also help.

Community
  • 1
  • 1
Mustafa Shabib
  • 798
  • 12
  • 35
  • I think this option would work best, but in doing a bit more with this app I realized I needed more customization and taking a true screen capture like this isn't the best way to go. I've decided to draw out the image in GDI instead which, while cumbersome, will give me the best flexibility for my overall scenario. Thanks for the tip though! – Scott Salyer Nov 09 '11 at 02:46
0

Well, If you want to take a screenshot of web page and save it is a image format(what ever you want) you can do like this....

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Web.Services;
using System.Text;
using System.Windows.Forms;//must be included for capturing screenshot

public partial class capture_webpage_screenshot : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
        Graphics graphics = Graphics.FromImage(bitmap as System.Drawing.Image);
        graphics.CopyFromScreen(25, 25, 25, 25, bitmap.Size);
        bitmap.Save(@"c:\screenshot\myscreenshot.bmp", ImageFormat.Bmp);

    }
}

and you have to follow these steps:

Just you have to do the following steps.

  • Right click the project name
  • Add reference -> .net tab and then choose system.windows.forms namespace then press ok button.
  • In .aspx code behind file you have to import the System.Windows.Formsnamespace and that’s it.

By customizing parameters used in CopyFromScreen() function, you can figure out how to capture the small portion of the screen, if required.

Create a folder and give folder path in c# code just like above i have given. You can customize the code as well and give the dynamic name of bitmap file every time it is generated.

I hope it will helps you...

Glory Raj
  • 17,397
  • 27
  • 100
  • 203