string extension = Path.GetExtension(UploadFile1.PostedFile.FileName).ToUpper();
string fileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
string path = Server.MapPath(@"~/UploadFile/" + fileName + extension);
UploadFile1.PostedFile.SaveAs(path); System.Drawing.Image image = System.Drawing.Image.FromFile(path);
System.Drawing.Image copyImage = System.Drawing.Image.FromFile(Server.MapPath(@"~/1.png"));
Graphics q = Graphics.FromImage(image);
q .DrawImage(copyImage, (copyImage.Width - 450) / 2, copyImage.Height / 2 + 225, 500, 100);
q .Dispose();
string newPath = Server.MapPath(@"~/UploadFile/" + fileName + "_new" + extension);
image.Save(newPath);
image.Dispose();
if (File.Exists(path))
{
File.Delete(path);
}
这样生产的时候。是把水印大小和图片大小定义死,才会居中,,如果图片大一点或者下一点,就不回居中,。。有什么好的方法解决没
string fileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
string path = Server.MapPath(@"~/UploadFile/" + fileName + extension);
UploadFile1.PostedFile.SaveAs(path); System.Drawing.Image image = System.Drawing.Image.FromFile(path);
System.Drawing.Image copyImage = System.Drawing.Image.FromFile(Server.MapPath(@"~/1.png"));
Graphics q = Graphics.FromImage(image);
q .DrawImage(copyImage, (copyImage.Width - 450) / 2, copyImage.Height / 2 + 225, 500, 100);
q .Dispose();
string newPath = Server.MapPath(@"~/UploadFile/" + fileName + "_new" + extension);
image.Save(newPath);
image.Dispose();
if (File.Exists(path))
{
File.Delete(path);
}
这样生产的时候。是把水印大小和图片大小定义死,才会居中,,如果图片大一点或者下一点,就不回居中,。。有什么好的方法解决没
http://topic.csdn.net/u/20100202/13/decda375-6498-4b91-b374-dfabaa61f905.html?66834
q .DrawImage(copyImage, (copyImage.Width - 450) / 2, copyImage.Height / 2 + 225, 500, 100);//这样定义 画水印的位置
X: image.width/2 - copyImage.width/2
Y: image.heigth/2 - copyImage.heigth/2