110,565
社区成员
发帖
与我相关
我的任务
分享
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile.FileName.Trim() != "")
{
//上传文件
string extension = Path.GetExtension(FileUpload1.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("web/") + fileName + extension;
FileUpload1.PostedFile.SaveAs(path);
//加文字水印,
System.Drawing.Image image = System.Drawing.Image.FromFile(path);
Graphics g = Graphics.FromImage(image);
g.DrawImage(image, 0, 0, image.Width, image.Height);
Font f = new Font("微软雅黑", 20);
Brush b = new SolidBrush(Color.Yellow);
g.DrawString("若要检查宏安全性设置,请单击 Microsoft Office 按钮,再单击“<程序名> 选项”,然后依次单击“信任中心”、“信任中心设置”。水印文字", f, b, 30, 20);
g.Dispose();
//保存加水印过后的图片,删除原始图片
string newPath = Server.MapPath("web/") + fileName + "_new" + extension;
image.Save(newPath);
image.Dispose();
if (File.Exists(path))
{
File.Delete(path);
}
Image1.ImageUrl = newPath;
}
}
Font f = new Font("微软雅黑", 20);
Brush b = new SolidBrush(Color.Black);
string _Value = "上岛咖啡几mmmmmm点思考第三方接口的肌肤看到房价的开发进度看房记的疯狂的肌肤";
SizeF _Size = gPrimalClothing.MeasureString(_Value, f, 200);//
// _Graphcis.DrawString(_Value, f, b, new RectangleF(30, 20, _Size.Width, _Size.Height));
gPrimalClothing.DrawString(_Value, f, b,new RectangleF(265, 70, _Size.Width, _Size.Height));
String drawString = "上岛咖啡几mmmmmm点思考第三方接口的肌肤看到房价的开发进度看房记的疯狂的肌肤";
Font f = new Font("微软雅黑", 20);
Brush b = new SolidBrush(Color.Black);
float width = 200.0F;
float height = 50.0F;
RectangleF drawRect = new RectangleF(265, 70, width, height);
// Draw rectangle to screen.
Pen blackPen = new Pen(Color.Transparent);
gPrimalClothing.DrawRectangle(blackPen,265, 70, width, height);
// Set format of string.
StringFormat drawFormat = new StringFormat();
drawFormat.Alignment = StringAlignment.Center;
// Draw string to screen.
gPrimalClothing.DrawString(drawString, f, b, drawRect, drawFormat);