Zoom out and upload images (Ajax + WebService)

Source: Internet
Author: User

Refer:

Ajax + WebService asynchronous brushless newest upload pictures: http://www.cnblogs.com/nianming/archive/2012/04/29/2476104.html

Image zoom post upload: http://weblogs.asp.net/markmcdonnell/archive/2008/03/09/resize-image-before-uploading-to-server.aspx

Plug-in: http://jquery.malsup.com/form/

After cutting an image, you have time to combine this example to achieve cutting first, then scaling and uploading.

You have not found any method for previewing before uploading (compatible with all browsers.

The Code is as follows:

Uploadimage. ashx

Using system; using system. collections. generic; using system. drawing; using system. drawing. drawing2d; using system. io; using system. LINQ; using system. web; namespace WebService {// <summary> // summary description for uploadimage /// </Summary> public class uploadimage: ihttphandler {public void processrequest (httpcontext context) {context. response. contenttype = "text/plain"; httppostedfile file = Co Ntext. Request. Files [0]; stream = file. inputstream; If (file! = NULL) {try {If (! Directory. exists (context. server. mappath (@ "uploaded-Files") {directory. createdirectory (context. server. mappath (@ "uploaded-Files");} // path of the folder where the image is saved: String Path = context. server. mappath ("~ /Uploaded-files/"); // a folder of images uploaded every day: String folder = datetime. now. tostring ("yyyymmdd"); // If the folder does not exist, create if (! Directory. exists (path + folder) {directory. createdirectory (path + folder);} // The Image Upload extension string type = file. filename. substring (file. filename. lastindexof ('. '); // Save the image file name string savename = guid. newguid (). tostring () + type; // Save the image bitmap originalbmp = new Bitmap (Stream); double origwidth = originalbmp. width; double origheight = originalbmp. height; double sngratio = origwidth/origheight; int thumbnailsize = 250; int newwidth, newheight; If (originalbmp. width> originalbmp. height) {newwidth = thumbnailsize; newheight = originalbmp. height * thumbnailsize/originalbmp. width;} else {newwidth = originalbmp. width * thumbnailsize/originalbmp. height; newheight = thumbnailsize;} bitmap newbmp = new Bitmap (originalbmp, newwidth, newheight); graphics ographics = graphics. fromimage (newbmp); ographics. smoothingmode = smoothingmode. antialias; ographics. interpolationmode = interpolationmode. highqualitybicubic; ographics. drawimage (originalbmp, 0, 0, newwidth, newheight); newbmp. save (path + folder + "/" + savename); originalbmp. dispose (); newbmp. dispose (); ographics. dispose (); context. response. write (Folder + "/" + savename);} catch {context. response. write ("Upload Failed") ;}}public bool isreusable {get {return false ;}}}}

Webform2.aspx

<% @ Page Language = "C #" autoeventwireup = "true" codebehind = "webform2.aspx. cs" inherits = "WebService. webform2" %> <! Doctype HTML> <HTML xmlns = "http://www.w3.org/1999/xhtml"> 

. Net uses request. files to indicate the files returned from the client.
Its attributes include:
Request. Files. Count indicates that several files have been uploaded.
Use request. Files [] to indicate the name of the original file control. Therefore, the property of request. Files is the property of the file control.
Httppostedfile indicates the file class to be returned. Because we may need to create an object to represent the returned object. You can use
Httppostedfile F = request. Files [N];

 

<input id="File1" type="file" runat="server" />

 

HttpPostedFile f = Request.Files[0];f.SaveAs(Server.MapPath("001.jpg"));

 

 

 

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.