Use Asp.net to implement simple text watermarks and asp.net text watermarks

Source: Internet
Author: User

Use Asp.net to implement simple text watermarks and asp.net text watermarks

It is often seen that a dynamic image is pasted on MOP, that is, a string is passed as a parameter to a dynamic web page, and an image with this string is generated, which is called a text watermark. Similar to the original pandatv series, as well as the later big trees and gold bars, they are quite interesting. It is very simple to write with Asp.net. 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 ("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:

<? 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.

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: info-contact@alibabacloud.com 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.