asp.net上传图片后,在图片上加入自己的背景字

       有时候我们在上传完一些自己的特殊图片后,想在别人传载的时候,可以表显出出自何方。这时我们就要在图片上加入一些背景字。下面给出我的代码
  前台:
   
< div >
    
        
< asp:Image  ID ="Image1"  runat ="server"  Height ="305px"  Width ="312px"   />
        
< asp:FileUpload  ID ="FileUpload1"  runat ="server"  Width ="243px"   />
        
< asp:Button  ID ="Button1"  runat ="server"  onclick ="Button1_Click"  Text ="上传图片"   />
    
    
</ div >


后台:

protected   void  Button1_Click( object  sender, EventArgs e)
        
{
            
string FileName;
            
string FileName1;
            
string FilePath;

            FileName 
= this.FileUpload1.PostedFile.FileName;
            FileName1 
= FileName.Substring(FileName.LastIndexOf("/")+1);
            FilePath 
= Request.PhysicalApplicationPath + "images/";
            
this.FileUpload1.PostedFile.SaveAs(FilePath + FileName1);

            System.Drawing.Image image1 
= System.Drawing.Image.FromFile(Server.MapPath("/images/" + FileName1));
            System.Drawing.Image NewImage 
= new Bitmap(image1.Width, image1.Height, PixelFormat.Format24bppRgb);
            Graphics g 
= Graphics.FromImage(NewImage);
            g.DrawImage(image1, 
00, image1.Width, image1.Height);
            Font f 
= new Font("楷书"int.Parse("28"));
            Brush b 
= new SolidBrush(Color.Red);
            g.DrawString(
"无名背景字", f, b, 10140);
            g.Dispose();
            System.Drawing.Image thubimages 
= NewImage.GetThumbnailImage(500500null,System.IntPtr.Zero);
            image1.Dispose();
            thubimages.Save(FilePath 
+ FileName1, ImageFormat.Jpeg);
            
this.Image1.ImageUrl = "/images/" + FileName1;
        }
试一下效果,你可以根据你的需求,来改变字的大小与色彩
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值