/// <summary> /// Navigate and return image cropped /// </summary> /// <param name="imgData">image object data</param> /// <returns>Web page image cropped.</returns> public static Bitmap GetWebsiteImage(ImageCropData imgData, string serverpath) { var width = imgData.Width; var height = imgData.Height; var y = imgData.Y; var x = imgData.X; Bitmap img = ImageUtil.GetWebSiteScreenCapture(imgData.Url, imgData.ContainerWidth, height, (int)y);//, 1024, 768); /*string imgPath = serverpath + "\\img_raw.jpg"; try { img.Save(imgPath); //b = true; } catch (Exception ex) { //lblMsg.Text = "The image can not be loaded, please try again in a few moments."; img.Dispose(); } */ Rectangle rect = new Rectangle { Width = (int)width, Height = (int)height }; img = cropAtRect(img, rect, x, y); return img; }
/// <summary> /// Return an image from the imageID param in RouteData value /// </summary> /// <param name="context">App Context</param> public void ProcessRequest(HttpContext context) { var imageId = RequestContext.RouteData.Values["imageID"]; var hasContent = imageId == null ? false : true; if(hasContent) { ImageCropData imgData = new ImageCropData(); using (ImageDBActions readImgFromDB = new ImageDBActions()) { imgData = readImgFromDB.GetImageData(imageId.ToString()); } string serverpath = RequestContext.HttpContext.Server.MapPath("Content/Images/Screenshots"); var image = ImageRenderMethods.GetWebsiteImage(imgData, serverpath); ImageConverter converter = new ImageConverter(); byte[] buffer = (byte[])converter.ConvertTo(image, typeof(byte[])); context.Response.ContentType = "image/jpg"; context.Response.BinaryWrite(buffer); context.Response.Flush(); image.Dispose(); } }
public static string CropImage(float x, float y, float width, float height, string url, float containerWidth) { var imageId = Guid.NewGuid().ToString(); imageId = Regex.Replace(imageId, "-", string.Empty, RegexOptions.IgnoreCase); var currentUrl = HttpContext.Current.Request.Url; //string urlGenerated = currentUrl.Scheme + "://"+ currentUrl.Authority + "/" + imageId; string urlGenerated = "http://localhost:1979/" + imageId; using (ImageDBActions newImgToDB = new ImageDBActions()) { var imgData = new ImageCropData { ImageID = imageId, X = x, Y = y, Url = url, Width = (int)width, Height = (int)height, ContainerWidth = (int)containerWidth }; newImgToDB.AddDataToDB(imgData); } return urlGenerated; }