Exemplo n.º 1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (IsPostBack)
     {
         GeneratingSmallerPicture draw = new GeneratingSmallerPicture();
         HttpPostedFile           file = Request.Files["Filedata"];
         file.SaveAs(Request.MapPath("/upload/" + file.FileName));
         string path;
         draw.MakeThumbnail(Request.MapPath("/upload/" + file.FileName), Request.MapPath("/upload/thumb/" + file.FileName), 300, 0, "W", out path);
     }
 }
Exemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            HttpPostedFile file = context.Request.Files["Filedata"];

            if (Path.GetExtension(file.FileName) == ".jpg")
            {
                file.SaveAs(context.Request.MapPath("/upload/" + file.FileName));
                GeneratingSmallerPicture draw = new GeneratingSmallerPicture();

                string path;

                draw.MakeThumbnail(context.Request.MapPath("/upload/" + file.FileName), context.Request.MapPath("/upload/thumb/" + Guid.NewGuid().ToString() + ".jpg"), 500, 400, "Cut", out path);
                File.Delete(context.Request.MapPath("/upload/" + file.FileName));
                context.Response.StatusCode = 200;

                context.Response.Write(path);
            }
            else
            {
                context.Response.StatusCode = 200;
                context.Response.Write("no");
            }
        }
Exemplo n.º 3
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            if (context.Request["action"] == null)  //上传初始图片
            {
                GeneratingSmallerPicture draw = new GeneratingSmallerPicture();
                HttpPostedFile           file = context.Request.Files["Filedata"];
                if (Path.GetExtension(file.FileName) == ".jpg")
                {
                    try
                    {
                        file.SaveAs(context.Request.MapPath("/upload/" + file.FileName));
                        string path;
                        string gid = Guid.NewGuid().ToString();
                        draw.MakeThumbnail(context.Request.MapPath("/upload/" + file.FileName), context.Request.MapPath("/upload/thumb/" + gid + ".jpg"), 500, 300, "Cut", out path);
                        File.Delete(context.Request.MapPath("/upload/" + file.FileName));
                        context.Response.Write("/upload/thumb/" + gid + ".jpg");
                    }
                    catch (Exception)
                    {
                        context.Response.Write("no");

                        throw;
                    }
                }
                else
                {
                    context.Response.Write("no");
                }
            }
            else
            {//裁剪图片
                try
                {
                    int    x   = int.Parse(context.Request["x"]);
                    int    y   = int.Parse(context.Request["y"]);
                    int    w   = int.Parse(context.Request["w"]);
                    int    h   = int.Parse(context.Request["h"]);
                    string url = context.Request["url"];
                    using (Bitmap map = new Bitmap(w, h))
                    {
                        using (Graphics g = Graphics.FromImage(map))
                        {
                            using (System.Drawing.Image img = System.Drawing.Image.FromFile(context.Request.MapPath(url)))
                            {
                                g.DrawImage(img, new Rectangle(0, 0, w, h), new Rectangle(x, y, w, h), GraphicsUnit.Pixel);
                                string fileName = Guid.NewGuid().ToString() + ".jpg";
                                map.Save(context.Request.MapPath("/upload/thumb/") + fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                                //File.Delete(context.Request.MapPath(url));
                                context.Response.Write("/upload/thumb/" + fileName);
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("no");
                    throw;
                }
            }
        }
Exemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                if (Context.Request["action"] == null)  //上传初始图片
                {
                    GeneratingSmallerPicture draw = new GeneratingSmallerPicture();
                    HttpPostedFile           file = Request.Files["Filedata"];
                    if (Path.GetExtension(file.FileName) == ".jpg")
                    {
                        try
                        {
                            file.SaveAs(Request.MapPath("/upload/" + file.FileName));
                            string path;
                            string gid = Guid.NewGuid().ToString();
                            draw.MakeThumbnail(Request.MapPath("/upload/" + file.FileName), Request.MapPath("/upload/thumb/" + gid + ".jpg"), 500, 300, "Cut", out path);
                            File.Delete(Request.MapPath("/upload/" + file.FileName));
                            Context.Response.Write("/upload/thumb" + gid + ".jpg");
                        }
                        catch (Exception)
                        {
                            Context.Response.Write("no");

                            throw;
                        }
                    }
                    else
                    {
                        Context.Response.Write("no");
                    }
                }
                else
                {//裁剪图片
                    try
                    {
                        int    x   = int.Parse(Context.Request["x"]);
                        int    y   = int.Parse(Context.Request["y"]);
                        int    w   = int.Parse(Context.Request["w"]);
                        int    h   = int.Parse(Context.Request["h"]);
                        string url = Context.Request["url"];
                        using (Bitmap map = new Bitmap(w, h))
                        {
                            Graphics g = Graphics.FromImage(map);
                            using (System.Drawing.Image img = System.Drawing.Image.FromFile(url))
                            {
                                g.DrawImage(img, new Rectangle(0, 0, w, h), new Rectangle(x, y, w, h), GraphicsUnit.Pixel);
                                string fileName = Guid.NewGuid().ToString() + ".jpg";
                                map.Save(Context.Request.MapPath("/upload/thubm/") + fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                                //File.Delete(Context.Request.MapPath(url));
                                Response.Write("/upload/thubm/" + fileName);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        Response.Write("no");
                        throw;
                    }
                }
            }
        }