上传加水印

//上传click 方法如下:

private void Button1_Click(object sender, System.EventArgs e)
{
string clientFullName = File1.PostedFile.FileName.ToString();
string extendName = clientFullName.Substring(clientFullName.LastIndexOf(".")+1).Trim().ToLower();
if(extendName == "jpg" || extendName == "gif")
{
string dateName = DateTime.Now.ToString("yyMMddhhmmss");
string dateFullName = Server.MapPath("test") + "//"+dateName+ "." + extendName;
this.File1.PostedFile.SaveAs(dateFullName);

System.Drawing.Image image = System.Drawing.Image.FromFile(dateFullName);
Graphics myGraphic = Graphics.FromImage(image);

Color myColor = Color.FromArgb(128,255,0,0);
SolidBrush myBrush = new SolidBrush(myColor);
Font myFont = new Font("Arial",16);
//Font myFont = new Font("Arial",image.Width/10); //大小根据图片决定字体大小
string myText = "HelloWorld";
// int imgX = image.Width/2 - (image.Width/10 * myText.Length)/2 ;
// int imgY = image.Height/2-(myFontHeight)/2; //决定位置

int imgX = 5;
int imgY = 5;
myGraphic.DrawString(myText, myFont, myBrush, imgX, imgY);
string waterMarkPath =Server.MapPath("test")+"//"+dateName+ "_wm." + extendName;
//image.Save(waterMarkPath);
//this.ibImage.ImageUrl = waterMarkPath;

//释放资源,以方便Del没加waterMark的图片
myGraphic.Dispose();
image.Dispose();
if(System.IO.File.Exists(dateFullName))
{
System.IO.File.Delete(dateFullName);
}
Response.Write("上传成功!");
}
else
{
Response.Write("格式不对");
}
}

client端加上效果会更好些

<INPUT id="File1" style="Z-INDEX: 103; LEFT: 120px; POSITION: absolute; TOP: 96px" type="file"
name="File1" runat="server" onpropertychange="document.all.ibImage.src='file:///'+this.value">

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值