Simple text watermark using ASP. NET

Source: Internet
Author: User

The Code is as follows:

<% @ Import Namespace = "System" %>
<% @ Import Namespace = "System. IO" %>
<% @ Import Namespace = "System. Drawing" %>

<% @ Page language = "vb" %>

<Script runat = "server">
Dim FilePath As String = Server. MapPath ("FengEr.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 (" 文 ", 30)
Dim B As Brush = new SolidBrush (Color. Green)
Dim s As String = Request. QueryString ("Str ")
G. DrawString (s, f, B, 20,290)
Image. Save (Response. OutputStream, System. Drawing. Imaging. ImageFormat. Jpeg)
G. Dispose ()
Image. Dispose ()
End Sub

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 test.jpg image and print the text in the font "文" at (20,290. The call method is simple:

Http: // localhost/Test. aspx? Str = Dicky's Blog!

You can set the printing position, Font, and image files. In addition, if English is used as a parameter, it can be displayed normally, but Chinese characters cannot be displayed, because the web. config settings of are incorrect and the following settings need to be performed:

<? Xml version = "1.0" encoding = "UTF-8"?>
<System. web>
<Globalization requestEncoding = "gb2312" responseEncoding = "gb2312" culture = "zh-CN" fileEncoding = "gb2312"/>
</System. web>

In this way, it can be displayed normally.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.