예제 #1
0
        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;
        }
예제 #2
0
        /// <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[]));

                //string imagePath = "~/Content/Images/Screenshots/" + imageId + ".jpg";
                context.Response.ContentType = "image/jpg";
                context.Response.BinaryWrite(buffer);
                context.Response.Flush();
                image.Dispose();
                //context.Response.WriteFile(imagePath);
            }
        }