如何在上传的图片上写字
|
源代码网整理以下很多时候需要在用户上传的图片上加上版权或者一些其他的附加文字信息,如何实现这样的功能,下面帖个简单实现的例子,起到抛砖引玉的作用。 ImageEditor.Visible = true; dis.Text+="文件大小:"+UploadFile.PostedFile.ContentLength+"字节数"; 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:listitem>26</asp:listitem> <asp:listitem>36</asp:listitem> <asp:listitem>48</asp:listitem> <asp:listitem>62</asp:listitem> </asp:dropdownlist> 标题字体: <asp:dropdownlist id="FontType" runat=server> <asp:listitem>黑体</asp:listitem> <asp:listitem>仿宋</asp:listitem> <asp:listitem>隶书</asp:listitem> <asp:listitem>楷书</asp:listitem> <asp:listitem>彩云</asp:listitem> <asp:listitem>新魏</asp:listitem> </asp:dropdownlist> <asp:button Text="Update Image" OnClick="UpdateBtn_Click" runat=server/> </asp:panel> </form> 源代码网整理以下 </body> 源代码网推荐 源代码网供稿. |
