//方法作用:生成水印图片
//sourcefile:要生成水印的图片文件
//watermarkfile:存放水印的图片文件
//savefile:存放水印的图片文件
public static bool makewaterimage(string sourcefile,string watermarkfile,string savefile)
{
bool result;
try
{
//原图
bitmap simage = new bitmap(sourcefile);
int swidth = simage.width;
int sheight = simage.height;
//水印图
bitmap wimage = new bitmap(watermarkfile);
int wwidth = wimage.width;
int wheight = wimage.height;
//make graphics.
graphics g = graphics.fromimage(simage);
int x; //临时变量
int y; //监时变量
int x1; //原图和水印图的宽度差
int y1; //原图和水印图的高度差
int w; //生成的水印图的宽度
int h; //生成的水印图的高度
int al; //alpha
int rl; //red
int gl; //green
int bl; //blue
if(swidth > wwidth)
{
x1 = swidth – wwidth;
y1 = sheight – wheight;
w = wwidth;
h = wheight;
}
else
{
x1 = 0;
y1 = 0;
w = swidth;
h = sheight;
}
//开始绘图
for(x = 1; x < w; x++)
{
for(y = 1; y < h; y++)
{
al = wimage.getpixel(x,y).a;
rl = wimage.getpixel(x,y).r;
gl = wimage.getpixel(x,y).g;
bl = wimage.getpixel(x,y).b;
al = 70;
if(rl + 25 < 255)
rl += 25;
if(gl + 25 < 255)
gl += 25;
if(bl + 25 < 255)
bl += 25;
g.drawellipse(new pen(new solidbrush(color.fromargb(al,rl,gl,bl))),x1+x,y1+y,1,1);
}
}
g.save();
simage.save(savefile);
result = true;
}
catch
{
result = false;
}
return result;
}
但这个不能在gif格式上加图片。。
