[高分]在asp.net中如何将一段文本生成一张透明的图片?
解决方案 »
- 如何在重新加载gridview的数据后,还保留其他文本框通过JavaScript输入的值?
- 数据库写入问题
- RadioButton的控制
- 在线等:来个SQL高手,创建表时,表名为变量,字段为变量,怎么建,用触发器
- 一开vs速度好慢,devenv.exe进程CPU占用率100%
- asp.net关于角色分配的问题
- 我想点机删除以后弹出是否删除的确认框,应该怎么做??
- 如何实现页面信息定时回写服务器,问题比较简单
- 关于RadioButtonList的选择统计问题?
- 怎样判断两个日期之间的时间差是否是14天??
- 用Exchange做邮件服务器,web页要做成163.com等门户网站的话该怎么做,用什么工具做(熟练asp.net),给个思路好吗??
- 关于指定iframe里显示的问题,急!!
给你一段往图片写文字的
,有个原始透明图,写进去,不知道行不行
<%@ Page Language="c#" Debug="true" Trace="true"%>
//debug,trace为测试时用的
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<html>
<script runat =server>
void UploadBtn_Click(Object sender, EventArgs e) {
UploadFile.PostedFile.SaveAs(Server.MapPath("test1.jpg"));
ImageEditor.Visible = true;
}
void UpdateBtn_Click(Object sender, EventArgs e) {
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath("test1.jpg"));
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("Lucida Sans Unicode", Int32.Parse(FontSize.SelectedItem.Text));
//font集,tnnd,没有使出中文来,那位老兄弄出来告诉我一声
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("test.jpg"), ImageFormat.JPEG);
} </script> <body> <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> <img src="test.jpg"> <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> <asp:button Text="Update Image" OnClick="UpdateBtn_Click" runat=server/> </h3>
</asp:panel> </form> </body>
</html>
http://www.codeproject.com/csharp/Water/Water_src.zip
这个代码,可以在现有图片生成水印和自加入文字
public ValidationImage(string Text, Font font, Color ForeColor, Color BackgroundColor)
{
Bitmap bm = new Bitmap(1,1);
Graphics gs = Graphics.FromImage(bm); bm = new Bitmap(Convert.ToInt32(gs.MeasureString(Text, font).Width),Convert.ToInt32(gs.MeasureString(Text, font).Height)); gs = Graphics.FromImage(bm);
gs.Clear(BackgroundColor);
gs.TextRenderingHint = TextRenderingHint.AntiAlias;
gs.DrawString(Text, font, new SolidBrush(ForeColor), 0, 0);
gs.Flush();
}