public JsonResult Cancel(string fileName)
        {
            var cropUtils = new CropImageUtility(this.UploadPath, this.OriginalPath, "");
            Dictionary <string, string> result = cropUtils.DeleteUploadImage(fileName);

            return(Json(result));
        }
        public ActionResult UploadFile(HttpPostedFileBase uploadFile)
        {
            if (uploadFile == null)
            {
                TempData["Upload_Result"] = "error";
                TempData["Upload_Msg"]    = "沒有上傳檔案";
                return(View());
            }

            try
            {
                var jo = new Dictionary <string, string>();

                var cropUtils = new CropImageUtility(this.UploadPath, this.OriginalPath, "");

                jo = cropUtils.ProcessUploadImage(uploadFile);

                TempData["Upload_Result"] = jo["result"];
                TempData["Upload_Msg"]    = jo["msg"];
            }
            catch (Exception ex)
            {
                TempData["Upload_Result"] = "Exception";
                TempData["Upload_Msg"]    = ex.Message;
            }
            return(View());
        }
Exemple #3
0
        public JsonResult Cancel(string fileName)
        {
            CropImageUtility cropUtils = new CropImageUtility(this.UploadPath, this.OriginalPath, string.Empty);
            var result = cropUtils.DeleteUploadImage(fileName);

            return(Json(result));
        }
Exemple #4
0
        protected void Button_Cancel_Click(object sender, EventArgs e)
        {
            CropImageUtility cropUtils = new CropImageUtility(this.UploadPath, this.OriginalPath, "");

            cropUtils.DeleteUploadImage(Session["Upload_File"].ToString());

            Session["Upload_File"] = null;
            Server.Transfer("Upload.aspx");
        }
        public JsonResult Save(string fileName)
        {
            var jo = new Dictionary <string, string>();

            var cropUtils = new CropImageUtility(this.UploadPath, this.OriginalPath, this.CropPath)
            {
                MaxWidth  = MaxWidth,
                MaxHeight = MaxHeight
            };

            var result = cropUtils.SaveUploadImageToOriginalFolder(fileName);

            if (!result["result"].Equals("Success", StringComparison.OrdinalIgnoreCase))
            {
                jo.Add("result", result["result"]);
                jo.Add("msg", result["msg"]);
            }
            else
            {
                try
                {
                    if (result["result"].Equals("Success", StringComparison.OrdinalIgnoreCase)
                        &&
                        !string.IsNullOrWhiteSpace(result["msg"]))
                    {
                        fileName = result["msg"].ToString();
                    }

                    var instance = new UploadImage
                    {
                        ID            = Guid.NewGuid(),
                        OriginalImage = fileName,
                        SelectionX1   = 0,
                        SelectionX2   = CropWidth,
                        SelectionY1   = 0,
                        SelectionY2   = CropHeight,
                        CreateDate    = DateTime.Now
                    };
                    instance.UpdateDate = instance.CreateDate;

                    Mapper.CreateMap <UploadImage, UploadImage2>();
                    var uploadImage2 = Mapper.Map <UploadImage2>(instance);

                    service.Add(uploadImage2);

                    jo.Add("result", "Success");
                    jo.Add("msg", string.Format(@"/{0}/{1}", OriginalFolder, fileName));
                    jo.Add("id", instance.ID.ToString());
                }
                catch (Exception ex)
                {
                    jo.Add("result", "Exception");
                    jo.Add("msg", ex.Message);
                }
            }
            return(Json(jo));
        }
Exemple #6
0
        public JsonResult CropImage(string id, int?x1, int?x2, int?y1, int?y2, int?imgWidth)
        {
            Dictionary <string, string> result = new Dictionary <string, string>();

            if (string.IsNullOrWhiteSpace(id))
            {
                result.Add("result", "error");
                result.Add("msg", "沒有輸入資料編號");
                return(Json(result));
            }
            if (!x1.HasValue || !x2.HasValue || !y1.HasValue || !y2.HasValue)
            {
                result.Add("result", "error");
                result.Add("msg", "裁剪圖片區域值有缺少");
                return(Json(result));
            }
            string id2 = id.Remove(0, 23);

            byte[]           arr       = Convert.FromBase64String(id2);
            MemoryStream     instance  = new MemoryStream(arr);
            Bitmap           oBitmap   = new Bitmap(instance);
            CropImageUtility cropUtils = new CropImageUtility();
            //不可以唯讀啊!
            int X1 = x1.Value;
            int X2 = x2.Value;
            int Y1 = y1.Value;
            int Y2 = y2.Value;

            if (imgWidth > 700)
            {
                X1 = X1 * imgWidth.Value / 700;
                X2 = X2 * imgWidth.Value / 700;
                Y1 = Y1 * imgWidth.Value / 700;
                Y2 = Y2 * imgWidth.Value / 700;
            }
            Dictionary <string, string> processResult = cropUtils.ProcessImageCrop
                                                        (
                oBitmap,
                new int[] { X1, X2, Y1, Y2 }
                                                        );

            if (processResult["result"].Equals("Success", StringComparison.OrdinalIgnoreCase))
            {
                result.Add("result", "OK");
                result.Add("msg", "");
                result.Add("CropImage", processResult["CropImage"].Remove(0, 1));
            }
            else
            {
                result.Add("result", processResult["result"]);
                result.Add("msg", processResult["msg"]);
            }
            return(Json(result));
        }
Exemple #7
0
        /// <summary>
        /// Saves the crop image.
        /// </summary>
        private void SaveCropImage()
        {
            bool isNullOfsectionValue = this.x1.Value == null &&
                                        this.x2.Value == null &&
                                        this.y1.Value == null &&
                                        this.y2.Value == null;

            if (isNullOfsectionValue)
            {
                ClientScriptHelper.ShowMessage(this.Page,
                                               "請選擇相片裁剪區域",
                                               RegisterScriptType.Start);
            }
            else
            {
                var cropUtils = new CropImageUtility(this.UploadPath, this.OriginalPath, this.CropPath);
                var result    = cropUtils.ProcessImageCrop
                                (
                    this.CurrentImage,
                    new int[]
                {
                    this.x1.Value.ConvertToInt(),
                    this.x2.Value.ConvertToInt(),
                    this.y1.Value.ConvertToInt(),
                    this.y2.Value.ConvertToInt()
                }
                                );

                if (!result["result"].Equals("Success", StringComparison.OrdinalIgnoreCase))
                {
                    ClientScriptHelper.ShowMessage(this.Page,
                                                   result["msg"],
                                                   RegisterScriptType.Start);
                }
                else
                {
                    //裁剪圖片檔名儲存到資料庫
                    _service.Update(this.ImageID, result["CropImage"]);

                    //如果有之前的裁剪圖片,則刪除
                    if (!string.IsNullOrWhiteSpace(result["OldCropImage"]))
                    {
                        cropUtils.DeleteCropImage(result["OldCropImage"]);
                    }

                    //載入裁剪圖片檔
                    LoadCropImage();

                    ClientScriptHelper.ShowMessage(this.Page,
                                                   "相片裁剪完成",
                                                   RegisterScriptType.Start);
                }
            }
        }
Exemple #8
0
        /// <summary>
        /// Processes the save.
        /// </summary>
        private void ProcessSave()
        {
            if (Session["Upload_File"] != null && !string.IsNullOrWhiteSpace(Session["Upload_File"].ToString()))
            {
                var fileName = Session["Upload_File"].ToString();

                var cropUtils = new CropImageUtility(this.UploadPath, this.OriginalPath, "");
                var result    = cropUtils.SaveUploadImageToOriginalFolder(fileName);

                if (!result["result"].Equals("Success", StringComparison.OrdinalIgnoreCase))
                {
                    ClientScriptHelper.ShowMessage(this.Page, result["msg"], RegisterScriptType.Start);
                }
                else
                {
                    var instance = new UploadImage
                    {
                        ID            = Guid.NewGuid(),
                        OriginalImage = fileName,
                        CreateDate    = DateTime.Now
                    };
                    instance.UpdateDate = instance.CreateDate;

                    _service.Add(instance);

                    this.HiddenField_ID.Value = instance.ID.ToString();

                    this.Image_Upload.ImageUrl = string.Format("{0}/{1}/{2}",
                                                               this.WebSiteRootPath,
                                                               this.OriginalFolder.Replace("~", ""),
                                                               fileName);

                    this.Button_Save.Visible   = false;
                    this.Button_Cancel.Visible = false;

                    if (!string.IsNullOrWhiteSpace(this.HiddenField_ID.Value))
                    {
                        this.Button_Crop.Visible = true;
                    }
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// Processes the upload.
        /// </summary>
        private void ProcessUpload()
        {
            string fileName = string.Empty;

            if (FileUpload1.HasFile)
            {
                HttpPostedFileBase uploadFile = new HttpPostedFileWrapper(FileUpload1.PostedFile);

                CropImageUtility            cropUtils = new CropImageUtility(this.UploadPath, this.OriginalPath, "");
                Dictionary <string, string> result    = cropUtils.ProcessUploadImage(uploadFile);

                if (!result["result"].Equals("Success", StringComparison.OrdinalIgnoreCase))
                {
                    Session["Upload_File"] = null;
                    ClientScriptHelper.ShowMessage(this.Page, result["msg"], RegisterScriptType.Start);
                }
                else
                {
                    Session["Upload_File"] = result["msg"];
                }
            }
        }
        public JsonResult Save(string fileName)
        {
            var jo = new Dictionary <string, string>();

            var cropUtils = new CropImageUtility(this.UploadPath, this.OriginalPath, "");

            var result = cropUtils.SaveUploadImageToOriginalFolder(fileName);

            if (!result["result"].Equals("Success", StringComparison.OrdinalIgnoreCase))
            {
                jo.Add("result", result["result"]);
                jo.Add("msg", result["msg"]);
                return(Json(jo));
            }

            try
            {
                var instance = new ImageCrop.Common.UploadImage
                {
                    ID            = Guid.NewGuid(),
                    OriginalImage = fileName,
                    CreateDate    = DateTime.Now
                };
                instance.UpdateDate = instance.CreateDate;

                _service.Add(instance);

                jo.Add("result", "Success");
                jo.Add("msg", string.Format(@"/{0}/{1}", OriginalFolder, fileName));
                jo.Add("id", instance.ID.ToString());
            }
            catch (Exception ex)
            {
                jo.Add("result", "Exception");
                jo.Add("msg", ex.Message);
            }
            return(Json(jo));
        }
Exemple #11
0
        public JsonResult Save(string fileName)
        {
            var jo = new Dictionary <string, string>();

            CropImageUtility cropUtils = new CropImageUtility(this.UploadPath, this.OriginalPath, string.Empty);
            var result = cropUtils.SaveUploadImageToOriginalFolder(fileName);

            if (!result["result"].Equals("success", StringComparison.OrdinalIgnoreCase))
            {
                jo.Add("result", result["result"]);
                jo.Add("msg", result["msg"]);

                return(Json(jo));
            }

            try
            {
                UploadImage instance = new UploadImage()
                {
                    ID            = Guid.NewGuid(),
                    OriginalImage = fileName,
                    CreateDate    = DateTime.Now,
                    UpdateDate    = DateTime.Now
                };

                service.Add(instance);

                jo.Add("result", "success");
                jo.Add("msg", string.Format(@"/{0}/{1}", OriginalFolder, fileName));
                jo.Add("id", instance.ID.ToString());

                return(Json(jo));
            }
            catch (Exception ex)
            {
                return(Json(MiscUtility.GetExceptionMsg(ex.Message)));
            }
        }
        public JsonResult CropImage(string id, int?x1, int?x2, int?y1, int?y2)
        {
            var result = new Dictionary <string, string>();

            if (string.IsNullOrWhiteSpace(id))
            {
                result.Add("result", "error");
                result.Add("msg", "沒有輸入資料編號");
                return(Json(result));
            }

            if (!x1.HasValue || !x2.HasValue || !y1.HasValue || !y2.HasValue)
            {
                result.Add("result", "error");
                result.Add("msg", "裁剪圖片區域值有缺少");
                return(Json(result));
            }

            Guid imageID;

            if (!Guid.TryParse(id, out imageID))
            {
                result.Add("result", "error");
                result.Add("msg", "資料編號錯誤");
                return(Json(result));
            }

            var instance = _service.FindOne(imageID);

            if (instance == null)
            {
                result.Add("result", "error");
                result.Add("msg", "資料不存在");
                return(Json(result));
            }

            var cropUtils = new CropImageUtility(this.UploadPath, this.OriginalPath, this.CropPath);

            Dictionary <string, string> processResult = cropUtils.ProcessImageCrop
                                                        (
                instance,
                new int[] { x1.Value, x2.Value, y1.Value, y2.Value }
                                                        );

            if (processResult["result"].Equals("Success", StringComparison.OrdinalIgnoreCase))
            {
                //裁剪圖片檔名儲存到資料庫
                _service.Update(instance.ID, processResult["CropImage"]);

                //如果有之前的裁剪圖片,則刪除
                if (!string.IsNullOrWhiteSpace(processResult["OldCropImage"]))
                {
                    cropUtils.DeleteCropImage(processResult["OldCropImage"]);
                }

                result.Add("result", "OK");
                result.Add("msg", "");
                result.Add("OriginalImage", string.Format(@"/{0}/{1}", this.OriginalFolder, processResult["OriginalImage"]));
                result.Add("CropImage", string.Format(@"/{0}/{1}", this.CropFolder, processResult["CropImage"]));
            }
            else
            {
                result.Add("result", processResult["result"]);
                result.Add("msg", processResult["msg"]);
            }
            return(Json(result));
        }