Design method for Avatar upload plugin compatible with IE (ASP. NET MVC)

Source: Internet
Author: User
Tags httpcontext

Two + plugins used

1. File Upload plugin uploadify

2. Image editing plugin jquery. Jcrop

Based on the MVC design pattern of ASP, the plug-in is designed.

Paste the following code:

View (. cshtml):

Controller:

  Public ActionResult uploadportrait () {return View ();                } [HttpPost] public actionresult upload (httppostedfilebase Filedata) {try {                Image image = Image.fromstream (Filedata.inputstream);                String ipath = Path.Combine ("Images", Path.getfilename (Filedata.filename));                String spath = Path.Combine (System.AppDomain.CurrentDomain.BaseDirectory, Ipath); Image.                Save (spath); Return Json (new {id = "0", mess = string. Format ("{0}{1}/{2}", BaseUrl, "Images", filedata.filename), IW = image. Width, ih = image.            Height}); } catch (Exception ex) {return Json (new {id = "1", mess = ex.            Message}); }} public ActionResult Trycrop (string img, int x, int y, int w, int h) {var imgpath = im            G.split ('/'); Image image = Image.FromFile (Path.Combine (HttpContext.Server.MapPatH ("~"), "Images", Imgpath[imgpath.count ()-1]); Crop (Image, W, h, x, y).            Save (Path.Combine (HttpContext.Server.MapPath ("~"), "Res", User.Identity.Name + "portrait.jpg"));        Return redirecttoaction ("Example", "account"); } public string BaseUrl {get {return Request.Url.Scheme + "://" + Req Uest.            Url.authority + Request.ApplicationPath.TrimEnd ('/') + '/';            }} [Nonaction] public static image Crop (image image, int width, int height, int x, int y) {            Bitmap bmp = New Bitmap (, PIXELFORMAT.FORMAT24BPPRGB); Bmp. Setresolution (image. HorizontalResolution, image.            VerticalResolution); using (Graphics graphic = graphics.fromimage (BMP)) {graphic.                SmoothingMode = Smoothingmode.antialias; Graphic.                Interpolationmode = Interpolationmode.highqualitybicubic; Graphic. Pixeloffsetmode = PixelOffsetMode.Highquality; Graphic.            DrawImage (Image, new Rectangle (0, 0, N, N), x, y, width, height, graphicsunit.pixel);        } return BMP; }

  

Design method for Avatar upload plugin compatible with IE (ASP. NET MVC)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.