/// <summary> /// Returns a WebShot image for the given URL using full provided sizing. /// </summary> /// <param name="url">The URL to capture.</param> /// <param name="width">The width of the hidden browser window. Affects HTML Rendering.</param> /// <param name="height">The height of the hidden browser window. Affects HTML Rendering.</param> /// <param name="webShotWidth">The width of the returned WebShot Image.</param> /// <param name="webShotHeight">The height of the returned WebShot Image.</param> /// <param name="autoSize">Autosizes the hidden browser window. Overrides width and height. Affects HTML Rendering.</param> /// <param name="autoSizeWebShot">Autosizes the WebShot image. Overrides WebShotHeight and WebShotWidth.</param> /// <param name="keepWebShotProportional">The WebShotHeight is kept in proportion with the WebShotWidth according to the hidden browser Width and Height proportion.</param> /// <returns>Returns the captured WebShot image as a System.Drawing.Bitmap.</returns> public static Bitmap GetWebShot(string url, int width, int height, int webShotWidth, int webShotHeight, bool autoSize, bool autoSizeWebShot, bool keepWebShotProportional) { WebShot webShot = new WebShot(url, width, height, webShotWidth, webShotHeight, autoSize, autoSizeWebShot, keepWebShotProportional); Bitmap bitmap = webShot.GetWebShotImage(); if (bitmap == null) { bitmap = (Bitmap)System.Drawing.Image.FromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("Julian.Imaging.Notavailable.jpg")); } return bitmap; }
/// <summary> /// Saves a WebShot image for the given URL using full provided sizing. /// </summary> /// <param name="fileName">The full path and file name to save to. If the file exists, it will be overwritten.</param> /// <param name="webShotQuality">Quality for WebShot Image. Values: 0 to 100.</param> /// <param name="url">The URL to capture.</param> /// <param name="webShotImageFormat">The format to save the image as.</param> /// <param name="width">The width of the hidden browser window. Affects HTML Rendering.</param> /// <param name="height">The height of the hidden browser window. Affects HTML Rendering.</param> /// <param name="webShotWidth">The width of the returned WebShot Image.</param> /// <param name="webShotHeight">The height of the returned WebShot Image.</param> /// <param name="autoSize">Autosizes the hidden browser window. Overrides width and height. Affects HTML Rendering.</param> /// <param name="autoSizeWebShot">Autosizes the WebShot image. Overrides WebShotHeight and WebShotWidth.</param> /// <param name="keepWebShotProportional">The WebShotHeight is kept in proportion with the WebShotWidth according to the hidden browser Width and Height proportion.</param> /// <returns>Returns one of the values from WebShotStatus.</returns> public static WebShotStatus SaveWebShot(string fileName, int webShotQuality, string url, ImageFormat webShotImageFormat, int width, int height, int webShotWidth, int webShotHeight, bool autoSize, bool autoSizeWebShot, bool keepWebShotProportional) { WebShot webShot = new WebShot(url, width, height, webShotWidth, webShotHeight, autoSize, autoSizeWebShot, keepWebShotProportional); webShot.WebShotImageQuality = webShotQuality; webShot.WebShotImageFormat = webShotImageFormat; return webShot.SaveWebShot(fileName); }
/// <summary> /// The Page Load Event /// </summary> /// <param name="sender">The sender</param> /// <param name="e">The parameters</param> protected void Page_Load(object sender, EventArgs e) { string url = string.Empty; int webShotWidth = 1024; int webShotHeight = 768; int width = 1024; int height = 768; bool autoSize = false; bool autoSizeWebShot = false; bool keepWebShotProportional = false; if (Request.QueryString["encodedurl"] != null) { url = HttpUtility.UrlDecode(Convert.ToString(Request.QueryString["encodedurl"])); } if (Request.QueryString["webShotWidth"] != null) { webShotWidth = Convert.ToInt32(Request.QueryString["webShotWidth"]); } if (Request.QueryString["webShotHeight"] != null) { webShotHeight = Convert.ToInt32(Request.QueryString["webShotHeight"]); } if (Request.QueryString["height"] != null) { height = Convert.ToInt32(Request.QueryString["height"]); } if (Request.QueryString["width"] != null) { width = Convert.ToInt32(Request.QueryString["width"]); } if (Request.QueryString["autoSize"] != null) { autoSize = Convert.ToBoolean(Request.QueryString["autoSize"]); } if (Request.QueryString["autoSizeWebShot"] != null) { autoSizeWebShot = Convert.ToBoolean(Request.QueryString["autoSizeWebShot"]); } if (Request.QueryString["keepWebShotProportional"] != null) { keepWebShotProportional = Convert.ToBoolean(Request.QueryString["keepWebShotProportional"]); } if (url == string.Empty) { return; } MemoryStream theStream = new MemoryStream(); ////WebShot.SaveWebShot(@"c:\test.bmp", 100, url, WebShot.ImageFormat.Bmp); WebShot webShot = new WebShot(); webShot.Url = url; webShot.Height = height; webShot.Width = width; webShot.WebShotHeight = webShotHeight; webShot.WebShotWidth = webShotWidth; webShot.AutoSize = autoSize; webShot.AutoSizeWebShot = autoSizeWebShot; webShot.KeepWebShotProportional = keepWebShotProportional; ////webShot.Timeout = 1; WebShot.WebShotStatus status = webShot.CaptureWebShotImage(); Bitmap bitmap = new Bitmap(Server.MapPath(@"~\images\notavailable.jpg")); if (status == WebShot.WebShotStatus.Captured) { bitmap = webShot.Image; } if (bitmap != null) { bitmap.Save(theStream, ImageFormat.Jpeg); Response.ContentType = "image/jpeg"; Response.BinaryWrite(theStream.ToArray()); } theStream.Dispose(); if (bitmap != null) { bitmap.Dispose(); } webShot.Dispose(); }