【www.gdgbn.com--word】

"文字水印

function wordwatermark(imagepath)
dim image
set image= server.createobject("persits.jpeg") " 建立对象
image.open server.mappath(imagepath) " 图片所在位置
image.canvas.font.color = &h000000 " 颜色,这里是设置成:黑
image.canvas.font.family = "宋体" " 设置字体
image.canvas.font.bold = false "是否设置成粗体
image.canvas.font.size = 26 "字体大小
image.canvas.font.quality = 4 " 文字清晰度
image.canvas.print image.originalwidth/2-170,image.originalheight-30, "水印文字" "水印文字
image.save server.mappath(imagepath) " 保存文件
set image= nothing
end function

"图片水印
function imagewatermark(imagepath)
set image = server.createobject("persits.jpeg")
"确定要加入水印的图片路径
photopath = server.mappath(imagepath)
image.open photopath
"打开水印图片
set logo = server.createobject("persits.jpeg")
logopath = server.mappath("logo.jpg") "水印的图片
logo.open logopath
logo.width = 121 "水印图片的大小
logo.height = 50
transition_color = &h0066cc
"将水印放置于上传图片中
image.drawimage image.width-150, image.height-59, logo,1,transition_color,90
"在这里可以更改水印所在的位置(photo.width-210,photo.height-40 这里我是放在了图片的右下角)还可以更改水印的透明度
"保存增加水印后的图片
image.save server.mappath(imagepath)

set photo = nothing
end function

代码二

asp.net教程 给图片加文字水印
文章分类:.net编程 关键字: asp.net 给图片加文字水印
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;
 }
 //还需要判断文件类型是否为图像类型,这里就不赘述了
 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; //字体大小
 float textwidth = text.length*fontsize; //文本的长度
 //下面定义一个矩形区域,以后在这个矩形里画上白底黑字
 float rectx = 0;
 float recty = 0;
 float rectwidth = text.length*(fontsize 8);
 float rectheight = fontsize 8;
 //声明矩形域
 rectanglef textarea = new rectanglef(rectx,recty,rectwidth,rectheight);
 font font = new font("宋体",fontsize); //定义字体
 brush whitebrush = new solidbrush(color.white); //白笔刷,画文字用
 brush blackbrush = new solidbrush(color.black); //黑笔刷,画背景用
 g.fillrectangle(blackbrush,rectx,recty,rectwidth,rectheight);
 g.drawstring(text,font,whitebrush,textarea);
 memorystream ms = new memorystream( );
 //保存为jpg类型
 bitmap.save(ms,imageformat.jpeg);
 //输出处理后的图像,这里为了演示方便,我将图片显示在页面中了
 response.clear();
 response.contenttype = "image/jpeg";
 response.binarywrite( ms.toarray() );
 g.dispose(); 
 bitmap.dispose();
 image.dispose();
}
  调用时很简单,
  addtexttoimg("me.jpg","family.man");


给图片增加水印代码三

文字水印实例代码

function wordwatermark(imagepath)
dim image
set image= server.createobject("persits.jpeg") " 建立对象
image.open server.mappath(imagepath) " 图片所在位置
image.canvas.font.color = &h000000 " 颜色,这里是设置成:黑
image.canvas.font.family = "宋体" " 设置字体
image.canvas.font.bold = false "是否设置成粗体
image.canvas.font.size = 26 "字体大小
image.canvas.font.quality = 4 " 文字清晰度
image.canvas.print image.originalwidth/2-170,image.originalheight-30, "水印文字" "水印文字
image.save server.mappath(imagepath) " 保存文件
set image= nothing
end function

"图片水印
function imagewatermark(imagepath)
set image = server.createobject("persits.jpeg")
"确定要加入水印的图片路径
photopath = server.mappath(imagepath)
image.open photopath
"打开水印图片
set logo = server.createobject("persits.jpeg")
logopath = server.mappath("logo.jpg") "水印的图片
logo.open logopath
logo.width = 121 "水印图片的大小
logo.height = 50
transition_color = &h0066cc
"将水印放置于上传图片中
image.drawimage image.width-150, image.height-59, logo,1,transition_color,90
"在这里可以更改水印所在的位置(photo.width-210,photo.height-40 这里我是放在了图片的右下角)还可以更改水印的透明度
"保存增加水印后的图片
image.save server.mappath(imagepath)

set photo = nothing
end function

本文来源:http://www.gdgbn.com/bangongshuma/27265/