在图片上加入图片版权信息
2024-07-21 02:24:02
供稿:网友
本例子主要是讲如何在上传图片上加入一个版权图片。
参数数明:filename, outfilename, copyrightfile如果在web下开发,一定要用虚拟路径。
如果是windows桌面程序,就用application.startuppath。
或者两者均用绝对路径。
在调用该方法时,必须先把图片上传到服务器,再在服务器端进行处理。
也必须要指定,原始的未处理的图片是否删除。
/// <summary>
/// 在图片上加入图片版权信息
/// </summary>
/// <param name="filename">原始图片</param>
/// <param name="outfilename">输出图片</param>
/// <param name="copyrightfile">版权图片</param>
/// <param name="deletefile">是否删除原始图片</param>
/// <param name="x">版权图片显示的x轴坐标</param>
/// <param name="y">版权图片显示的y轴坐标</param>
public void createcopyrightimage(string filename, string outfilename, string copyrightfile, bool deletefile, float x, float y)
{
system.drawing.image image = system.drawing.image.fromfile(filename);
system.drawing.image c_image = system.drawing.image.fromfile(copyrightfile);
system.drawing.bitmap output = new system.drawing.bitmap(image);
system.drawing.graphics g = system.drawing.graphics.fromimage(output);
g.drawimage(c_image, x, y);
string extend = filename.substring(filename.lastindexof(".") + 1).tolower();
switch(extend)
{
case "bmp" :
output.save(outfilename, system.drawing.imaging.imageformat.bmp);
break;
case "jpg" :
output.save(outfilename, system.drawing.imaging.imageformat.jpeg);
break;
case "gif" :
output.save(outfilename, system.drawing.imaging.imageformat.gif);
break;
case "icon" :
output.save(outfilename, system.drawing.imaging.imageformat.icon);
break;
case "png" :
output.save(outfilename, system.drawing.imaging.imageformat.png);
break;
case "tif" :
output.save(outfilename, system.drawing.imaging.imageformat.tiff);
break;
default :
output.save(outfilename, system.drawing.imaging.imageformat.jpeg);
break;
}
g.dispose();
output.dispose();
image.dispose();
c_image.dispose();
if(deletefile)
{
system.io.file.delete(filename);
}
}