1,给图片添加图片水印EmployeeMessage/EditEmployee.aspx
system.drawing.image image = system.drawing.image.fromfile(path);
system.drawing.image copyimage = system.drawing.image.fromfile( server.mappath(".") + "/alex.gif");
graphics g = graphics.fromimage(image);
g.drawimage(copyimage, new rectangle(image.width-copyimage.width, image.height-copyimage.height, copyimage.width, copyimage.height), 0, 0, copyimage.width, copyimage.height, graphicsunit.pixel);
g.dispose();
//保存加水印过后的图片,删除原始图片
string newpath = server.mappath(".") + "/uploadfile/" + filename + "_new" + extension;
image.save(newpath);
image.dispose();
if(file.exists(path))
{
file.delete(path);
}
response.redirect(newpath);
}
}
2,实现另存为的效果
这个主题不知道已经被多少人问过多少遍了,无论是ASP.NET,还是PHP还是什么别的CGI,似乎这也算做一个“永恒”的话题了。
其实解决方案很简单(无论哪个CGI平台都是如此),只是一个header而已:
复制C#代码保存代码Response.ContentType = "image/jpeg";
Response.AppendHeader("Content-Disposition","attachment; filename=SailBig.jpg");
Response.TransmitFile( Server.MapPath("~/images/sailbig.jpg") );
Response.End();