asp.net to add a watermark to a picture

Source: Internet
Author: User
asp.net

Program code
<body>
<asp:label id= "Dis" runat=server/>
<form enctype= "Multipart/form-data" Runat=server id= "Form1" >
Select Upload file: <input id= "UploadFile" Type=file runat=server name= "UploadFile" >
<asp:button text= "Upload me!" Runat=server id= "Button1"/>
<asp:panel id= "Imageeditor" Visible=false runat=server>

Image width: <asp:textbox id= "width" runat= "Server"/>
Image height: <asp:textbox id= "height" runat= "Server"/>
Text title: <asp:textbox id= "Caption" runat= "Server"/>
Title Font size: <asp:dropdownlist id= "fontsize" runat= "Server" >
<asp:ListItem>14</asp:ListItem>
<asp:ListItem>18</asp:ListItem>
<asp:ListItem>26</asp:ListItem>
<asp:ListItem>36</asp:ListItem>
<asp:ListItem>48</asp:ListItem>
<asp:ListItem>62</asp:ListItem>
</asp:DropDownList>
Title font: <asp:dropdownlist id= "Fonttype" runat= "Server" >
<asp:ListItem> Bold </asp:ListItem>
<asp:ListItem> Imitation </asp:ListItem>
<asp:ListItem> Official Script </asp:ListItem>
<asp:ListItem> Regular Script </asp:ListItem>
<asp:ListItem> Choi Wan </asp:ListItem>
<asp:ListItem> New Wei </asp:ListItem>
</asp:DropDownList>
<asp:button text= "Update Image" runat= "Server" id= "Button2"/>
</asp:Panel>
</form>
</body>

Background code
Description
1. Add pictures and text can not coexist is that you can only use a
2. Add the picture when you have to ensure that you are added watermark picture 3.png in (you can change the other, the program will also change)
Must have this folder that holds the picture, uploadfile (can change oneself other, the procedure also wants to change)
3. To change the text, the position of the picture must be changed in the program.

Program code
public void Uploadbtn_click (Object Sender,eventargs e) {
String filename;
String filename1;
String[] filename2;
int q;
Filename=uploadfile.postedfile.filename;
Filename2=filename. Split (new char[] {' \ \} ');
Q=filename2. GetUpperBound (0);
FILENAME1=FILENAME2[Q];
Dis. text= "Upload filename:" +filename1+ "<br>";
UploadFile.PostedFile.SaveAs (Server.MapPath (filename1));
Imageeditor.visible = true;
Dis. text+= "File size:" +uploadfile.postedfile.contentlength+ "number of bytes";
image1.src=filename1;
}

void Updatebtn_click (Object sender, EventArgs e) {
String filename1;
FILENAME1=IMAGE1.SRC;

Add text watermark, note that the code here and the following image watermark code can not coexist
System.Drawing.Image Image = System.Drawing.Image.FromFile (Server.MapPath (filename1));
System.Drawing.Image newimage = new Bitmap (Image. Width,image. HEIGHT,PIXELFORMAT.FORMAT32BPPRGB);
Graphics g = graphics.fromimage (newimage);
G.drawimage (image,0,0,image. Width,image. Height);
Font f= new Font (FontType.SelectedItem.Text, Int32.Parse (FontSize.SelectedItem.Text));
Brush B = new SolidBrush (color.antiquewhite);
g.DrawString (Caption.text, F, b, 100, 140);
G.dispose ();


Add Image Watermark
System.Drawing.Image Image = System.Drawing.Image.FromFile (Server.MapPath (filename1));//Original
System.Drawing.Image newimage = System.Drawing.Image.FromFile (Server.MapPath ("3.png"));//This object is an added watermark
Graphics g = graphics.fromimage (image);
G.drawimage (NewImage, new Rectangle) (image. Width-newimage.width, image. Height-newimage.height, NewImage. Width, NewImage. Height), 0, 0, NewImage. Width, NewImage. Height, GraphicsUnit.Pixel);
G.dispose ();

Add text watermark
System.Drawing.Image thumbimage = newimage. Getthumbnailimage (image. Width,image. Height,null,new IntPtr ());
Image. Dispose ();
Thumbimage.save (Server.MapPath (filename1), imageformat.jpeg);

Add Image Watermark
Image. Save (Server.MapPath ("uploadfile/" +filename1));


IMAGE1.SRC = filename1;
Caption.text= "";
}



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.