コード例 #1
0
        protected void btnCrop_Click(object sender, EventArgs e)
        {
            // Crop Image Here & Save
            string fileName     = Path.GetFileName(imgUpload.ImageUrl);
            string filePath     = Path.Combine(Server.MapPath("~/Fotos"), fileName);
            string cropFileName = "";
            string cropFilePath = "";

            if (File.Exists(filePath))
            {
                try
                {
                    System.Drawing.Image orgImg   = System.Drawing.Image.FromFile(filePath);
                    Rectangle            CropArea = new Rectangle(
                        Convert.ToInt32(X.Value),
                        Convert.ToInt32(Y.Value),
                        Convert.ToInt32(W.Value),
                        Convert.ToInt32(H.Value));

                    Bitmap bitMap = new Bitmap(CropArea.Width, CropArea.Height);
                    using (Graphics g = Graphics.FromImage(bitMap))
                    {
                        g.DrawImage(orgImg, new Rectangle(0, 0, bitMap.Width, bitMap.Height), CropArea, GraphicsUnit.Pixel);
                    }
                    cropFileName = "crop_" + fileName;
                    cropFilePath = Path.Combine(Server.MapPath("~/Fotos"), cropFileName);
                    bitMap.Save(cropFilePath);
                    string     id_usuario = Convert.ToString(Session["id_usuario"]);
                    DTOUsuario user       = new DTOUsuario();
                    CADUsuario process    = new CADUsuario();
                    user.Id   = Convert.ToInt32(id_usuario);
                    user.Foto = ("Fotos/" + cropFileName);
                    if (process.ModificarFotoPerfilUsuario(user) == 0)
                    {
                        /* panCrop.Visible = false;
                         * FU1.Visible =true;
                         * Label8.Visible = true;
                         * picture1.Visible = true;
                         * lblMsg.Visible = true;
                         * Image3.Visible = true;
                         * btnUpload.Visible = true;
                         * seleccionarfoto.Visible = true;*/
                        Response.Redirect("PerfilAdmin.aspx");
                        //ScriptManager.RegisterClientScriptBlock(this, GetType(), "mensaje", "modificacionphoto();", true);
                    }
                    else
                    {
                        ScriptManager.RegisterClientScriptBlock(this, GetType(), "problem", "problema();", true);
                    }
                    // Response.Redirect("~/Fotos/" + cropFileName, false);
                }
                catch (Exception ex)
                {
                    ScriptManager.RegisterClientScriptBlock(this, GetType(), "problem", "problema();", true);
                }
            }
        }