asp+ File Upload Enhancement instance

Source: Internet
Author: User
According to the actual upload file name Save (not test.jpg) picture can be changed size, the figure on the handwriting (optional font, I set up all Chinese, ^_^. Size), the font color problem is not resolved.

<%@ Page language= "C #" debug= "true" trace= "true"%>
<%@ Import namespace= "System.IO"%>
<%@ Import namespace= "System.Drawing"%>
<%@ Import namespace= "System.Drawing.Imaging"%>
<script runat =server>
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;
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.red);
g.DrawString (Caption.text, F, B, 10, 140);
G.dispose ();
System.Drawing.Image thumbimage = newimage. Getthumbnailimage (Int32.Parse (Width.text), Int32.Parse (Height.text), null,0);
Image. Dispose ();
Thumbimage.save (Server.MapPath (filename1), imageformat.jpeg);
image1.src=filename1;
Caption.text= "";

}

</script>

<body>
<asp:label id= "Dis" runat=server/>
<form enctype= "Multipart/form-data" runat=server>


Select File to Upload: <input id= "UploadFile" Type=file runat=server>

<asp:button text= "Upload me!" runat=server/>


<asp:panel id= "Imageeditor" Visible=false runat=server>



Image width: <asp:textbox id= "width" runat=server/>

Image Height: <asp:textbox id= "height" runat=server/> <br>

Text Caption: <asp:textbox id= "Caption" runat=server/>

Caption 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>
Caption 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> founder Yau </asp:listitem>
<asp:listitem> Chinese Cloud </asp:listitem>
</asp:dropdownlist>

<asp:button text= "Update Image" runat=server/>

</asp:panel>

</form>

</body>


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.