The file name is saved (test.jpg is used) on the upload page. You can change the size of the image and write it on the image (optional font. I set it to all Chinese characters, ^_^. Large
Small), does not solve the font color problem.
<% @ Page Language = "c #" Debug = "true" Trace = "true" %>
<% @ Import Namespace = "System. IO" %>
<% @ Import Namespace = "System. Drawing" %>
<% @ Import Namespace = "System. Drawing. Imaging" %>
<Html>
<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 File Name:" + filename1 + "<br> ";
UploadFile. PostedFile. SaveAs (Server. MapPath (filename1 ));
ImageEditor. Visible = true;
Dis. Text + = "file size:" + UploadFile. PostedFile. ContentLength + "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>
<H3>
Select File To Upload: <input id = "UploadFile" type = file runat = server>
<Asp: button Text = "Upload Me! "OnClick =" UploadBtn_Click "runat = server/>
<Hr>
<Asp: panel id = "ImageEditor" Visible = false runat = server>
<H3>
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> </asp: listitem>
<Asp: listitem> Imitation Song </asp: listitem>
<Asp: listitem> example book </asp: listitem>
<Asp: listitem> example book </asp: listitem>
<Asp: listitem> 正 </asp: listitem>
<Asp: listitem> 文 </asp: listitem>
</Asp: dropdownlist>
<Asp: button Text = "Update Image" OnClick = "UpdateBtn_Click" runat = server/>
</H3>
</Asp: panel>
</Form>
</Body>
</Html>