asp.net (VB) to add watermark text to the picture

Source: Internet
Author: User

' Specify the picture you want to add the watermark text to
Dim img as Image = Image.FromFile (Server.MapPath ("~/upload/1.jpg"))
' Create a Bitmap object for the drawing operation (you cannot directly manipulate a format other than BMP, possibly)
Dim Bitmap as New bitmap (343, 498)
' The font to draw the text
Dim F as New Font ("Microsoft Ya-Black", fontstyle.underline)
' Text content
Dim str as String = Textbox5.text
' Create an object to draw an image
Dim g as Graphics = Graphics.fromimage (bitmap)
' The coordinates of the line
Dim x1, x2, y1, y2, s1, S2 as Integer
X1 = CType (TextBox1.Text, Integer)
x2 = CType (TextBox2.Text, Integer)
Y1 = CType (TextBox3.Text, Integer)
y2 = CType (Textbox4.text, Integer)
' The coordinates of the text
S1 = CType (Textbox6.text, Integer)
S2 = CType (Textbox7.text, Integer)
' Limit the scope of the drawing
G.drawimage (IMG, 0, 0, 343, 498)
' Draw text
g.DrawString (str, F, brushes.red, S1, S2)
' Draw line
G.drawline (pens.white, x1, x2, y1, y2)
' Save path after drawing is complete
Dim iimg as String = "~/upload/11.jpg"
Dim img1 as String = Server.MapPath (iimg)
' JPG image quality parameters
Dim EP as Imaging.encoderparameters = New imaging.encoderparameters
' Image quality value
Ep. Param (0) = New imaging.encoderparameter (Imaging.Encoder.Quality, CLng (Textbox8.text))
' Read the image content in streaming mode
Dim codecs as imaging.imagecodecinfo () = Imaging.ImageCodecInfo.GetImageEncoders
Dim ici as Imaging.imagecodecinfo
For each codec as Imaging.imagecodecinfo in codecs
If codec. MimeType = "Image/jpeg" Then
ICI = Codec
End If
Next
' Save the Painted image.
Bitmap. Save (IMG1, ICI, EP)
Image1.imageurl = iimg
' Release object
G.dispose ()
Bitmap. Dispose ()
Img. Dispose ()

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.