Use Asp.net to implement text watermarks. Here is a simple method. Although it is simple, it is very practical and easy to understand and modify.
| The code is as follows: |
Copy code |
<% @ Import Namespace = "System" %> <% @ Import Namespace = "System. IO" %> <% @ Import Namespace = "System. Drawing" %> <% @ Page language = "vb" %> <Script runat = "server"> Dim FilePath As String = Server. MapPath ("Talk. JPG ") Sub Page_Load (Sender As Object, E As EventArgs) Dim image As System. Drawing. Image = System. Drawing. Image. FromFile (FilePath) Dim g As Graphics = Graphics. FromImage (image) G. DrawImage (image, 0, 0, image. Width, image. Height) Dim f As Font = new Font (" 文 ", 40) Dim B As Brush = new SolidBrush (Color. Black) Dim s As String = Left (Request. QueryString ("str"), 7) G. DrawString (s, f, B, 20,190) Image. Save (Response. OutputStream, System. Drawing. Imaging. ImageFormat. Jpeg) G. Dispose () Image. Dispose () End Sub </Script> |
You only need to save this code as an aspx file, such as Test. aspx. Put it in wwwroot (assuming your virtual directory is default ). Make another image of Talk. JPG and print the text in the font "文" in (20,190. The call method is simple:
Http: // localhost/Test. aspx? Str = test failed!
You can set the printing position, font, and image files. In addition, if e is used as the parameter, it can be displayed normally, but Chinese cannot be displayed, because Asp.net web. if the config settings are incorrect, the following settings are required:
| The code is as follows: |
Copy code |
<? Xml version = "1.0" encoding = "UTF-8"?> <Configuration> <System. web> <Globalization requestEncoding = "gb2312" responseEncoding = "gb2312" culture = "zh-CN" fileEncoding = "gb2312"/> </System. web> </Configuration> |
In this way, it can be displayed normally.