C # upload images, generate thumbnails, and generate text or image watermarks

Source: Internet
Author: User
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml"> 

 

View plain Copy to clipboard Print ?
  1. Using system;
  2. Using system. Data;
  3. Using system. configuration;
  4. Using system. Web;
  5. Using system. Web. Security;
  6. Using system. Web. UI;
  7. Using system. Web. UI. webcontrols;
  8. Using system. Web. UI. webcontrols. webparts;
  9. Using system. Web. UI. htmlcontrols;
  10. Using system. drawing;
  11. Public partial class _ default: system. Web. UI. Page
  12. {
  13. Protected void page_load (Object sender, eventargs E)
  14. {
  15. }
  16. Protected void button#click (Object sender, eventargs E)
  17. {
  18. String filename = fileupload1.filename;
  19. String nowpath = server. mappath (".") + "\\";
  20. Filename = nowpath + filename;
  21. // Save the source Image
  22. Fileupload1.saveas (filename );
  23. System. Drawing. Image image, newimage, syimage;
  24. System. Drawing. image. getthumbnailimageabort callb = NULL;
  25. Image = system. Drawing. image. fromfile (filename );
  26. Syimage = system. drawing. image. fromfile (server. mappath (". ") +" \ "+" .gif "); // to place a" .gif "file under the directory, you can download from the Internet: http://www.baidu.com/img/baidu.gif
  27. // Save the thumbnail
  28. Newimage = image. getthumbnailimage (100,100, callb, new intptr ());
  29. Newimage. Save (filename + ".w.tu.png ");
  30. Newimage. Dispose ();
  31. // Process the original image
  32. Graphics G = graphics. fromimage (image );
  33. Font F = new font ("", 16 );
  34. Brush B = new solidbrush (colortranslator. fromhtml ("# ff0000 "));
  35. String addtext = "text watermark content ";
  36. G. drawstring (addtext, F, B, 10, 10 );
  37. G. drawimageunscaled (syimage, 50, 50 );
  38. // G. drawimage (newimage, 50, 50, 100,100 );
  39. G. Dispose ();
  40. // Generate a watermark image
  41. Image. Save (filename + ". .png ");
  42. Image. Dispose ();
  43. Syimage. Dispose ();
  44. Image1.imageurl = fileupload1.filename;
  45. Image2.imageurl = fileupload1.filename + ". .png ";
  46. Image3.imageurl = fileupload1.filename + ". .png ";
  47. }
  48. }
Related Article

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.