[高分]在asp.net中如何将一段文本生成一张透明的图片?

解决方案 »

  1.   

    还要透明阿
    给你一段往图片写文字的
    ,有个原始透明图,写进去,不知道行不行
    <%@ 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>
      

  2.   

    帮你查了查,好像没有现成的
    http://www.codeproject.com/csharp/Water/Water_src.zip
    这个代码,可以在现有图片生成水印和自加入文字
      

  3.   

    找到这个函数
    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(); 
      } 
      

  4.   

    http://community.csdn.net/Expert/topic/3041/3041776.xml?temp=.4296686
      

  5.   

    在ASP.NET下实现数字和字符相混合的验证码 http://dev.csdn.net/develop/article/22/22618.shtm