Using asp.net to realize simple text watermark _ Practical Skills

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 ("XXFarEastFont-Xingkai", 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
</script>


Just save this code as an ASPX file, such as Test.aspx. Then put it in the wwwroot (assuming your virtual directory is the default). To do a test.jpg picture, you can print the text of the font "XXFarEastFont-Xingkai" in this position (20, 290). Calling the method is simple:

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

For print locations and fonts and picture files can be set themselves. In addition, if the use of English as a parameter can be normal display, and the Chinese will not be able to display the situation because the ASP.net Web.config settings are incorrect, you need to do the following settings:

<?xml version= "1.0" encoding= "Utf-8"?>
<configuration>
<system.web>
<globalization requestencoding= "gb2312" responseencoding= "gb2312" culture= "ZH-CN" fileencoding= "gb2312"/>
</system.web>
</configuration>

This way, you can display it normally.

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.