' Text watermark
function Wordwatermark (ImagePath)
Dim image
Set image= Server.CreateObject ("Persits.jpeg") ' establishes an object
Image.open Server.MapPath (ImagePath) ' Image location
Image.canvas.font.color = &h000000 ' color, here is set to: Black
image.canvas.font.family = "XXFarEastFont-Arial" set font
Image.canvas.font.bold = False ' is set to bold
Image.canvas.font.size = 26 ' font size
image.canvas.font.quality = 4 ' Text clarity
Image.canvas.print image.originalwidth/2-170,image.originalheight-30, "watermark text" ' Watermark text
Image.Save Server.MapPath (ImagePath) ' Save file
Set image= Nothing
End Function
' Image watermark
function Imagewatermark (ImagePath)
Set image = Server.CreateObject ("Persits.jpeg")
' Determine the path of the picture to be added to the watermark
Photopath = Server.MapPath (ImagePath)
Image.open Photopath
' Open watermark Picture
Set logo = Server.CreateObject ("Persits.jpeg")
Logopath = Server.MapPath ("logo.jpg") ' Watermark picture
Logo.open Logopath
Logo.width = 121 ' Size of watermark picture
Logo.height = 50
Transition_color = &h0066cc
' Place the watermark in the upload image
Image.drawimage image.width-150, image.height-59, logo,1,transition_color,90
' Here you can change the location of the watermark (photo.width-210,photo.height-40 here I put it in the lower-right corner of the picture) you can also change the transparency of the watermark
' Save the picture after adding the watermark
Image.Save Server.MapPath (ImagePath)
Set photo = Nothing
End Function
Code two
asp.net tutorial to add text watermark to a picture
Article Category:. NET programming Keywords: asp.net to the picture with a text watermark
Using System.Drawing;
Using System.IO;
Using System.Drawing.Imaging;
private void Addtexttoimg (string filename,string text)
{
if (!file.exists (MapPath (filename))
{
throw new FileNotFoundException ("The file don t exist!");
}
if (Text = = String.Empty)
{
Return
}
You also need to determine whether the file type is an image type, so here's the
System.Drawing.Image image = System.drawing.image.fromfile (MapPath (filename));
Bitmap bitmap = new Bitmap (image,image.width,image.height);
Graphics g = graphics.fromimage (bitmap);
float fontsize = 12.0f; Font size
float textwidth = text.length*fontsize; Length of text
The following defines a rectangular area, in which the white and black characters are later painted in the rectangle.
float rectx = 0;
float recty = 0;
float rectwidth = text.length* (fontsize 8);
float rectheight = FontSize 8;
Declaring a rectangular field
RectangleF textarea = new RectangleF (rectx,recty,rectwidth,rectheight);
Font font = new Font ("Song Body", FontSize); Defining fonts
Brush Whitebrush = new SolidBrush (color.white); White brush, painting text with
Brush Blackbrush = new SolidBrush (color.black); Black Brush, drawing background
G.fillrectangle (Blackbrush,rectx,recty,rectwidth,rectheight);
g.DrawString (Text,font,whitebrush,textarea);
MemoryStream ms = new MemoryStream ();
Save as JPG type
Bitmap.save (Ms,imageformat.jpeg);
Output processing image, here for demonstration convenience, I will display the picture in the page
Response.Clear ();
Response.ContentType = "Image/jpeg";
Response.BinaryWrite (Ms.toarray ());
G.dispose ();
Bitmap.dispose ();
Image.dispose ();
}
It's simple to call,
Addtexttoimg ("Me.jpg", "Family.man");
Add watermark code to picture three
Text Watermark Instance Code
Function Wordwatermark (ImagePath)
Dim image
Set Image= Server.CreateObject ("persits.jpeg") ' Establish object
Image.open Server.MapPath (ImagePath) ' picture location
Image.canvas.font.color = &h000000 ' color, here is set to: Black
image.canvas.font.family = "Arial" to set the font
Image.canvas.font.bold = False ' is set to bold
Image.canvas.font.size = 26 ' Font size image.canvas.font.quality = 4 ' text sharpness
Image.canvas.print image.originalwidth/2-170,image.originalheight-30, ' Watermark text "' Watermark text
Image.Save Server.MapPath (imagepath) ' Save file
Set image= nothing
End Function
' Image watermark
function Imagewatermark (ImagePath)
Set image = Server.CreateObject ("Persits.jpeg")
' Determine the path of the picture to be added to the watermark
Photopath = Server.MapPath (ImagePath)
Image.open Photopath
' Open watermark Picture
Set logo = Server.CreateObject ("Persits.jpeg")
Logopath = Server.MapPath ("logo.jpg") ' Watermark picture
Logo.open Logopath
Logo.width = 121 ' Size of watermark picture
Logo.height = 50
Transition_color = &h0066cc
' Place the watermark in the upload image
Image.drawimage image.width-150, image.height-59, logo,1,transition_color,90
' Here you can change the location of the watermark (photo.width-210,photo.height-40 here I put it in the lower-right corner of the picture) you can also change the transparency of the watermark
' Save the picture after adding the watermark
Image.Save Server.MapPath (ImagePath)
Set photo = Nothing
End Function