本例子主要是讲如何在上传图片上加入一个版权图片。
参数数明: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);
}
}
本文地址:http://com.8s8s.com/it/it44049.htm