C # webform site picture Save code

Source: Internet
Author: User

Good hard to generate a two-dimensional code, and then to achieve the click "Save Picture", pop-up selection path to save the effect.

Look

    stringQrcodeurl =""; stringUsername =""; protected voidBtnsave_click (Objectsender, EventArgs e) {        //Create a pictureBitmap image = Create_imgcode (Qrcodeurl,5); //Save Picture        stringServer_saveurl = Server.MapPath ("~/") +"Upload\\qrcode";        Saveimg (Server_saveurl, image); FileDownload (Server_saveurl+"\\"+ Username +". PNG"); }    /// <summary>      ///generate two-dimensional code images/// </summary>      /// <param name= "Codenumber" >a string to generate a two-dimensional code</param>           /// <param name= "Size" >size Size</param>      /// <returns>Two-dimensional code image</returns>       PublicBitmap Create_imgcode (stringCodenumber,intsize) {        //creating a two-dimensional code generation classQrcodeencoder Qrcodeencoder =NewQrcodeencoder (); //Setting the encoding modeQrcodeencoder.qrcodeencodemode =Qrcodeencoder.encode_mode.        BYTE; //Setting the Encoding measurement degreeQrcodeencoder.qrcodescale =size; //set the encoded versionQrcodeencoder.qrcodeversion =0; //set encoding error correctionQrcodeencoder.qrcodeerrorcorrect =qrcodeencoder.error_correction.        M //generate two-dimensional code imagesSystem.Drawing.Bitmap image =Qrcodeencoder.encode (Codenumber); returnimage; }     /// <summary>      ///Save the picture on the server side/// </summary>      /// <param name= "strpath" >Save Path</param>      /// <param name= "img" >Image</param>       Public stringSaveimg (stringstrpath, Bitmap img) {        //save picture to directory        if(!directory.exists (strpath)) {            //if the current directory does not exist, createdirectory.createdirectory (strpath); }        //file name        stringfilename = strpath +"/"+ Username +". PNG"; if(file.exists (filename)) {returnfilename; } img.        Save (filename, System.Drawing.Imaging.ImageFormat.Png); returnfilename; }    /// <summary>    ///WebForm Save the picture in the client/// </summary>    /// <param name= "Fullfilename" ></param>    Private voidFileDownload (stringfullfilename) {FileInfo DownloadFile=NewFileInfo (fullfilename);        Response.Clear ();        Response.ClearHeaders (); Response.Buffer=false; Response.ContentType="Application/octet-stream"; Response.appendheader ("content-disposition","attachment;filename="+Httputility.urlencode (Downloadfile.fullname, System.Text.Encoding.UTF8)); Response.appendheader ("Content-length", DownloadFile.Length.ToString ());        Response.WriteFile (Downloadfile.fullname);        Response.Flush ();    Response.End (); }

Are online search, looking for a long time in the thought of saving the image to the server, and then download from the server to the customer service side.

C # webform site picture Save code

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.