欢迎光临
我们一直在努力

一个制作水印的方法-.NET教程,评论及其它

建站超值云服务器,限时71元/月

//方法作用:生成水印图片

//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格式上加图片。。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 一个制作水印的方法-.NET教程,评论及其它
分享到: 更多 (0)

相关推荐

  • 暂无文章