如何截图javascript图表?

时间:2014-06-25 07:40:55

标签: javascript asp.net screenshot

我想在网页上获得js图表的截图。 Html和CSS方面工作完美,但js百分比图表不显示..我怎么能这样做?

int width = 920;
    int height = 440;
    byte[] screenshot = null;
    var t = new Thread(() =>
    {
        using (var ms = new MemoryStream())
        {
            // The screenshot object contains a 640x480 
            // screenshot 
            var bitmap = new HtmlToBitmapConverter()
                .Render(uri,
                        new Size(width, height));
            bitmap.Save(ms, ImageFormat.Png);
            screenshot = ms.ToArray();
        }
    });
    t.SetApartmentState(ApartmentState.STA);
    t.Start();
    t.Join();

    // Here we have the JPEG encoded bytes of the image - we can
    // just save them to a file like so...
    string path = Server.MapPath("Images/XCM/" + DateTime.Now.ToString("dd/MM/yyy").Substring(0, 10).Replace("/", "").Replace(".", "") + ".Png");
    if (File.Exists(path))
    {
        File.Delete(path);
    }

    using (var f = File.Create(path))
    {
        f.Write(screenshot, 0, screenshot.Length);
    }

enter image description here

0 个答案:

没有答案