In our use of QQ upload Avatar, registered user account will be encountered upload images, and according to their own requirements on the image to cut, this is how to achieve na?
This article mainly introduces the asp.net mvc to upload avatar and cut the function, share for everybody reference. Specifically as follows:
The screenshot of the running effect is as follows:
The specific code is as follows:
Front Code
<link href= "~/content/fineuploader.css" rel= "stylesheet"/> <link "href= ~/content/jquery". Jcrop.min.css "rel=" stylesheet "/> <link href=" ~/content/crop.min.css "rel=" "stylesheet"/> <script src= "~/" Scripts/jquery-1.8.2.min.js "></script> <script src=" ~/scripts/jquery.fineuploader-3.1.min.js "> </script> <script src= "~/scripts/jquery. Jcrop.min.js "></script> <script src=" ~/scripts/crop.js "></script> <div id=" Jquery-wrapped-fine-uploader "></div> <div id=" message "></div> <div id=" Crop_wrap "> < Div id= "Crop_holder" > <div id= "crop_area" class= "Border" > </div> <div id=" Preview_area "> <div id=" Preview_title " ; current Avatar </div> <div id= "Preview_large_text" class= "Preview-text" >180pxx180px</div> <div id= "PR
Eview_large_wrap "class=" Border "> </div> </div> & lt;/div> <div id= "crop_operation" style= "Display:none";
> <form id= "form_crop" action= "/home/index" method= "POST" > <input type= "hidden" name= "x" id= "X" > <input type= "hidden" name= "y" id= "y" > <input type= "hidden" name= "W" id= "W" > <input type= "hidden" n Ame= "H" id= "H" > <input type= "hidden" name= "imgsrc" id= "imgsrc" > <input id= "crop_operation_submit" type = "Submit" value= "Cut and save"/><span id= "crop_operation_msg" style= "Display:none" class= "Green" ></span> &
lt;/form> </div> <div id= "croped_message" class= "green" ></div> </div>
Background Code
Public ActionResult Index () {return View (); ///<summary>///Save thumbnails///</summary>///<param name= "form" ></param>///<return s></returns> [HttpPost] public actionresult Index (formcollection form) {int x = Convert.ToInt32 (form["x
"]);
int y = Convert.ToInt32 (form["y"]);
int w = Convert.ToInt32 (form["w"]);
int h = Convert.ToInt32 (form["H"]); String imgsrc = form["Imgsrc"]. Substring (0, form["imgsrc").
LastIndexOf ("?"));
String path = Imghandler.cutavatar (imgsrc, X, Y, W, h);
Save path Viewbag.path = path;
return View (); ///<summary>///upload avatar///</summary>///<param name= "Qqfile" ></param>///<retur ns></returns> [HttpPost] public actionresult processupload (string qqfile) {try {string UPLOADFO
Lder = "/upload/original/" + DateTime.Now.ToString ("yyyymm") + "/";
String imgname = DateTime.Now.ToString ("DDHHMMSSFF"); String Imgtype = Qqfile. Substring (Qqfile.
LastIndexOf ("."));
String uploadpath = "";
Uploadpath = Server.MapPath (Uploadfolder); if (!
Directory.Exists (Uploadpath)) {directory.createdirectory (Uploadpath); using (var InputStream = Request.inputstream) {using (var Fliestream = new FileStream (Uploadpath + imgname
+ Imgtype, FileMode.Create)) {Inputstream.copyto (fliestream);
} return Json (new {success = true, message = Uploadfolder + imgname + imgtype});
catch (Exception e) {return Json (new {fail = true, message = E.message});
}
}
The above is to achieve asp.net mvc upload image plus clipping part of the code, small series to share for everyone's reference, I hope to help you learn.