.net上传图片文件,生成缩略图,并写上版权信息
By  落亦随风 发表于 2007-4-13 1:07:26 


.net上传图片文件,生成缩略图,并写上版权信息

private void Button1_Click(object sender, System.EventArgs e)
  {
   if(File1.PostedFile.FileName!=null)
   {   
   string namestr = Path.GetFileName(File1.PostedFile.FileName);//提取文件名  
   File1.PostedFile.SaveAs(Server.MapPath(".")+@"\"+namestr);
   Image2.Visible=true;
   Image2.ImageUrl=Server.MapPath(".")+@"\"+namestr;
   System.Drawing.Image image,aNewImage;
   image=System.Drawing.Image.FromStream(File1.PostedFile.InputStream);
   decimal width=image.Width;
   decimal height=image.Height;
   int newwidth,newheight;
   if(width>height)
   {
    newwidth=150;
    newheight=(int)(height/width*150);
   }
   else
   {
    newheight=150;
    newwidth=(int)(width/height*150);
   }
   aNewImage=image.GetThumbnailImage(newwidth,newheight,null,IntPtr.Zero);
   Bitmap output=new Bitmap(aNewImage);
   Graphics g=Graphics.FromImage(output);
   g.DrawString(TextBox1.Text.Trim(),new Font("Courier New", 9),new SolidBrush(Color.Red),60,60);//写版权信息及文本格式及位置
   output.Save(Server.MapPath(".")+@"\s_"+namestr,System.Drawing.Imaging.ImageFormat.Jpeg);
   Image1.Visible=true;
   Image1.ImageUrl=Server.MapPath(".")+@"\s_"+namestr;
   }
  }

 

 
阅读全文 | 回复(0) | 引用通告 | 编辑

发表评论:

    昵称:
    密码: (游客无须输入密码)
    主页:
    标题:

 
站点公告
站点日历
最新日志
最新评论
最新留言
友情链接
站点统计
日志搜索
用户登陆

 
进入用户中心 e起有米社区 辰米网络科技