图片上传增加水印。删除临时文件出错,在线等待高手指点。最好能给个不用临时文件的。。

/// <summary>
/// 在图片上生成图片水印
/// </summary>
/// <param name="Path">原服务器图片路径</param>
/// <param name="Path_syp">生成的带图片水印的图片路径</param>
/// <param name="Path_sypf">水印图片路径</param>
public static void AddShuiYinPic(string Path, string Path_sypf, string Path_syp, string addText)
{

float picTransparency = 0.7f;
float[][] nArray ={ new float[] {1, 0, 0, 0, 0},
new float[] {0, 1, 0, 0, 0},
new float[] {0, 0, 1, 0, 0},
new float[] {0, 0, 0, picTransparency, 0},
new float[] {0, 0, 0, 0, 1}};
System.Drawing.Imaging.ColorMatrix matrix = new System.Drawing.Imaging.ColorMatrix(nArray);
System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes();
attributes.SetColorMatrix(matrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap);

System.Drawing.Image image = System.Drawing.Image.FromFile(Path);
System.Drawing.Image copyImage = System.Drawing.Image.FromFile(Path_sypf);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);
g.DrawImage(copyImage, new System.Drawing.Rectangle(image.Width - copyImage.Width - 70, image.Height - copyImage.Height, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, System.Drawing.GraphicsUnit.Pixel, attributes);
g.DrawImage(image, 0, 0, image.Width, image.Height);
float xpos = 0;
float ypos = 0;
Font crFont = null;
SizeF crSize = new SizeF();
int[] sizes = new int[] { 16, 14, 12, 10, 8, 6, 4 };

for (int i = 0; i < 7; i++)
{
crFont = new Font("Arial", sizes[i], FontStyle.Bold);
crSize = g.MeasureString(addText, crFont);

if ((ushort)crSize.Width < (ushort)image.Width)
break;
}

xpos = ((float)image.Width * (float).99) - (crSize.Width / 2);
ypos = ((float)image.Height * (float).99) - crSize.Height;
SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(153, 255, 255, 255));
StringFormat StrFormat = new StringFormat();
StrFormat.Alignment = StringAlignment.Center;
g.DrawString(addText, crFont, semiTransBrush, xpos, ypos, StrFormat);

image.Save(Path_syp);

g.Flush();
g.Dispose();
image.Dispose();

}

AddShuiYinPic(bigPicPath, @"D:\分站3\代码\NewSub\Css\images\top_logo.gif", bigPicPath_sy, DateTime.Now.Year.ToString());

if (File.Exists(bigPicPath))
{

File.Delete(bigPicPath); 在这里报错了,正由另一进程使用,因此该进程无法访问该文件。

}

给各位网店卖家推荐个淘宝专业储存空间吧!--巴比豆
巴比豆相册功能多:,超级搬家, 批量搞定你的店铺所有商品;
免费动态计数器统计:可以实现店铺浏览量; 每天来多少客源,轻松掌握;
宝贝模板:百余款模板免费用, 一键式到淘宝.非常方便!新手也能很快学会使用;
批量上传,批量下载.批量加水印,批量改大小, 批量帖图,防止图片被盗!
可以支持批量图片上传..也支持批量图片贴图到宝贝页面中..
如有题还可以随时联系在线客服为你解决疑难杂症.
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

大家正在搜

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网