示例#1
0
        public AccountPage()
        {
            Title            = "Post";
            _favorite        = null;
            _mainStackLayout = new StackLayout
            {
                BackgroundColor = Color.FromHex("101010"),
                Padding         = new Thickness(5),
            };
            relaodFavorites();
            ScrollView scrollView = new ScrollView {
                Content = _mainStackLayout
            };
            RefreshView refreshView    = new RefreshView();
            ICommand    refreshCommand = new Command(() =>
            {
                relaodFavorites();
                refreshView.IsRefreshing = false;
            });
            ToolbarItem ToolBarUpload = new ToolbarItem
            {
                Text = "Upload Image"
            };

            ToolBarUpload.Clicked += async delegate
            {
                await Navigation.PushAsync(new UploadPage());
            };
            this.ToolbarItems.Add(ToolBarUpload);
            refreshView.Command = refreshCommand;
            refreshView.Content = scrollView;
            Content             = refreshView;
        }
示例#2
0
        public JsonResult Save(string fileName)
        {
            Dictionary <string, string> jo = new Dictionary <string, string>();

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

            cropUtils.MaxWidth  = this.MaxWidth;
            cropUtils.MaxHeight = this.MaxHeight;

            Dictionary <string, string> 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();
                    }

                    UploadImage2 instance = new UploadImage2();
                    instance.ID            = Guid.NewGuid();
                    instance.OriginalImage = fileName;
                    instance.SelectionX1   = 0;
                    instance.SelectionX2   = this.CropWidth;
                    instance.SelectionY1   = 0;
                    instance.SelectionY2   = this.CropHeight;
                    instance.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));
        }
        //=========================================================================================
        // Crop Image

        #region -- ProcessImageCrop --
        /// <summary>
        /// Processes the image crop.
        /// </summary>
        /// <param name="currentImage">The current image.</param>
        /// <param name="sectionValue">The section value.</param>
        /// <returns></returns>
        public Dictionary <string, string> ProcessImageCrop(UploadImage2 currentImage, int[] sectionValue)
        {
            Dictionary <string, string> result = new Dictionary <string, string>();

            try
            {
                //取得裁剪的區域座標
                int section_x1 = sectionValue[0];
                int section_x2 = sectionValue[1];
                int section_y1 = sectionValue[2];
                int section_y2 = sectionValue[3];

                //取得裁剪的圖片寬高
                int width  = section_x2 - section_x1;
                int height = section_y2 - section_y1;

                //讀取原圖片
                System.Drawing.Image sourceImage = System.Drawing.Image.FromFile
                                                   (
                    string.Format(@"{0}\{1}", this.OriginalPath, currentImage.OriginalImage)
                                                   );

                //從原檔案取得裁剪圖片
                System.Drawing.Image cropImage = this.CropImage(
                    sourceImage,
                    new Rectangle(section_x1, section_y1, width, height)
                    );

                //將採剪下來的圖片做縮圖處理
                Bitmap resizeImage = this.ResizeImage(cropImage, new Size(this.CropWidth, this.CropHeight));

                //將縮圖處理完成的圖檔儲存為JPG格式
                string fileName = String.Concat(MiscUtility.makeGUID().Replace("-", string.Empty).Substring(0, 20), ".jpg");
                string savePath = string.Format(@"{0}\{1}", this.CropPath, fileName);
                SaveJpeg(savePath, resizeImage, 100L);

                //釋放檔案資源
                resizeImage.Dispose();
                cropImage.Dispose();
                sourceImage.Dispose();

                //如果有之前的裁剪圖片,暫存既有的裁剪圖片檔名
                string oldCropImageFileName = string.Empty;
                if (!string.IsNullOrWhiteSpace(currentImage.CropImage))
                {
                    oldCropImageFileName = currentImage.CropImage;
                }

                //JSON
                result.Add("result", "Success");
                result.Add("OriginalImage", currentImage.OriginalImage);
                result.Add("CropImage", fileName);
                result.Add("OldCropImage", oldCropImageFileName);
            }
            catch (Exception ex)
            {
                result.Add("result", "Exception");
                result.Add("msg", ex.Message);
            }
            return(result);
        }
示例#4
0
 public void loadData()
 {
     _favorite = null;
     _favorite = ResquestAPI.getPost();
 }
    protected void btnBackImage_Click(object sender, EventArgs e)
    {
        try
        {
            string productid = Request.QueryString["product"];
            if (productid != null)
            {
                string ImageFile = "";
                if (UploadImage.HasFile)
                {
                    string imgPath   = "~/Upload/images/";
                    string thumbPath = "~/Upload/thumbnails/";
                    string smallPath = "~/Upload/small/";

                    ImageFile = Path.GetFileName(Server.MapPath(UploadImage.PostedFile.FileName));
                    ImageFile = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "-back-" + ImageFile;
                    thumbPath = thumbPath + ImageFile;
                    System.Drawing.Bitmap bmpUploadedImage = new System.Drawing.Bitmap(UploadImage.PostedFile.InputStream);
                    System.Drawing.Image  objImage         = ScaleImage(bmpUploadedImage);
                    objImage.Save(Server.MapPath(thumbPath), ImageFormat.Png);

                    smallPath = smallPath + ImageFile;
                    System.Drawing.Image objImage2 = ScaleImage2(bmpUploadedImage);
                    objImage2.Save(Server.MapPath(smallPath), ImageFormat.Png);

                    imgPath = imgPath + ImageFile;
                    UploadImage.SaveAs(MapPath(imgPath));
                }
                else
                {
                    ImageFile = lblImage.Text;
                }

                string ImageFile2 = "";
                if (UploadImage2.HasFile)
                {
                    string imgPath   = "~/Upload/images/";
                    string thumbPath = "~/Upload/thumbnails/";
                    string smallPath = "~/Upload/small/";

                    ImageFile2 = Path.GetFileName(Server.MapPath(UploadImage2.PostedFile.FileName));
                    ImageFile2 = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "-back-" + ImageFile2;
                    thumbPath  = thumbPath + ImageFile2;
                    System.Drawing.Bitmap bmpUploadedImage = new System.Drawing.Bitmap(UploadImage2.PostedFile.InputStream);
                    System.Drawing.Image  objImage         = ScaleImage(bmpUploadedImage);
                    objImage.Save(Server.MapPath(thumbPath), ImageFormat.Png);

                    smallPath = smallPath + ImageFile2;
                    System.Drawing.Image objImage2 = ScaleImage2(bmpUploadedImage);
                    objImage2.Save(Server.MapPath(smallPath), ImageFormat.Png);

                    imgPath = imgPath + ImageFile2;
                    UploadImage2.SaveAs(MapPath(imgPath));
                }
                else
                {
                    ImageFile2 = lblImage2.Text;
                }

                string ImageFile3 = "";
                if (UploadImage3.HasFile)
                {
                    string imgPath   = "~/Upload/images/";
                    string thumbPath = "~/Upload/thumbnails/";
                    string smallPath = "~/Upload/small/";

                    ImageFile3 = Path.GetFileName(Server.MapPath(UploadImage3.PostedFile.FileName));
                    ImageFile3 = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "-back-" + ImageFile3;
                    thumbPath  = thumbPath + ImageFile3;
                    System.Drawing.Bitmap bmpUploadedImage = new System.Drawing.Bitmap(UploadImage3.PostedFile.InputStream);
                    System.Drawing.Image  objImage         = ScaleImage(bmpUploadedImage);
                    objImage.Save(Server.MapPath(thumbPath), ImageFormat.Png);

                    smallPath = smallPath + ImageFile3;
                    System.Drawing.Image objImage2 = ScaleImage2(bmpUploadedImage);
                    objImage2.Save(Server.MapPath(smallPath), ImageFormat.Png);

                    imgPath = imgPath + ImageFile3;
                    UploadImage3.SaveAs(MapPath(imgPath));
                }
                else
                {
                    ImageFile3 = lblImage3.Text;
                }

                int result = 0;

                result = obj_product.AddOtherProductImage(productid, ImageFile, ImageFile2, ImageFile3);
                if (result != 0)
                {
                    lblMessage.ForeColor = Color.Green;
                    lblMessage.Text      = "Product Other Image Added!";
                    BindBackImg(productid);
                }
            }
            else
            {
                lblMessage.ForeColor = Color.Red;
                lblMessage.Text      = "Go View Product & select Product!";
            }
        }
        catch (Exception ex)
        {
            lblMessage.ForeColor = Color.Red;
            lblMessage.Text      = ex.Message;
        }
    }