Simple Example of Image Upload (watermarking, thumbnails, and remote storage) (applied to 51aspx.com)
The source code: http://51aspx.com/CV/ImageUpload
Today, I saw the message sent by xiongeee.ArticleUse the fileupload control to upload images, automatically generate thumbnails, and automatically generate watermarks with text and images
I think that the function of automatically saving remote images may be more practical. I wrote one myself if I found a lot on the Internet and it was incomplete.
Write a test to implement the following functions:
A practical example of uploading images
Image Upload: Create a thumbnail and add a text watermark.
51aspx.png: watermark image
Remote Image Capturing (save to local) supports JPG, GIF, BMP, and PNG
After the image is captured, it is automatically named after auto + date + Original Name
Enter the remote image address (HTML supported)
Here, only the remote saving part is posted.CodeFor other parts, please download the attachment and read it. It is a complete small example. Many people may think it is a good dish, but I think it is helpful to most people and I hope you will give more criticism and guidance.
1 // Automatically save remote Images
2
3 WebClient Client = New WebClient ();
4 // Standby REG:
5 RegEx Reg = New RegEx ( " IMG [^>] *? SRC \ s * = \ s *(? :\ " ( ? < 1 > [ ^ \ " ] *) \ " | ' (? <1> [^ \ ' ] * ) ' ) ", Regexoptions. ignorecase );
6 Matchcollection m = Reg. Matches (textbox1.text );
7
8 Foreach (Match math In M)
9 {
10 String Imgurl = Math. Groups [ 1 ]. Value;
11 // Add yymmdd to the original image name and upload it
12 RegEx regname = New RegEx ( @" \ W + .(? : JPG | GIF | BMP | PNG) " , Regexoptions. ignorecase );
13
14 String Strnewimgname = Datetime. Now. tow.datestring (). Replace ( " - " , "" ) + Regname. Match (imgurl). tostring ();
15
16 Try
17 {
18 // Save image
19 Client. downloadfile (imgurl, server. mappath ( " Imgupload/auto/ " + Strnewimgname ));
20
21 }
22 Catch
23 {
24}
25 Finally
26 {
27
28}
29
30 Client. Dispose ();
31 }
32
33
Download full source http://51aspx.com/CV/ImageUpload