最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

asp.net實現(xiàn)生成縮略圖及給原始圖加水印的方法示例

 更新時間:2017年10月09日 11:57:24   作者:happymagic  
這篇文章主要介紹了asp.net實現(xiàn)生成縮略圖及給原始圖加水印的方法,結(jié)合具體實例形式分析了asp.net圖片的縮略圖與水印操作相關實現(xiàn)技巧,需要的朋友可以參考下

本文實例講述了asp.net實現(xiàn)生成縮略圖及給原始圖加水印的方法。分享給大家供大家參考,具體如下:

using System.IO;
using System.Drawing.Imaging;
private void Button1_ServerClick(object sender, System.EventArgs e) 
{
  Graphics g=null;
  System.Drawing.Image upimage=null;
  System.Drawing.Image thumimg=null;
  System.Drawing.Image simage=null;
  Bitmap outputfile=null;
  try 
  {
    string extension = Path.GetExtension(File1.PostedFile.FileName).ToUpper();
    string filename = DateTime.Now.ToString("yyyyMMddhhmmss");
    string smallpath = Server.MapPath(".")+"/smallimg/";
    string bigpath = Server.MapPath(".")+"/bigimg/";
    int width,height,newwidth,newheight;
    System.Drawing.Image.GetThumbnailImageAbort callb =new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
    if(!Directory.Exists(smallpath))
    Directory.CreateDirectory(smallpath);
    if(!Directory.Exists(bigpath))
    Directory.CreateDirectory(bigpath);
    Stream upimgfile = File1.PostedFile.InputStream;
    string simagefile = Server.MapPath("a8logo.jpg"); //要加水印的文件
    simage=System.Drawing.Image.FromFile(simagefile);
    upimage= System.Drawing.Image.FromStream(upimgfile); //上傳的圖片
    width = upimage.Width;
    height = upimage.Height;
    if(width>height) 
    {
      newwidth=200;
      newheight =(int)((double)height/(double)width * (double)newwidth);
    } else 
    {
      newheight=200;
      newwidth=(int)((double)width/(double)height * (double)newheight);
    }
    thumimg = upimage.GetThumbnailImage(newwidth,newheight,callb,IntPtr.Zero);
    outputfile=new Bitmap(upimage);
    g=Graphics.FromImage(outputfile);
    g.DrawImage(simage,new Rectangle(upimage.Width-simage.Width,upimage.Height-simage.Height,upimage.Width,upimage.Height),0,0,upimage.Width,upimage.Height,GraphicsUnit.Pixel);
    string newpath = bigpath + filename + extension; //原始圖路徑
    string thumpath = smallpath + filename + extension; //縮略圖路徑
    outputfile.Save(newpath);
    thumimg.Save(thumpath);
    outputfile.Dispose();
  }
  catch(Exception ex) 
  {
    throw ex;
  }
  finally 
  {
    if(g!=null)
    g.Dispose();
    if(thumimg!=null)
    thumimg.Dispose();
    if(upimage!=null)
    upimage.Dispose();
    if(simage!=null)
    simage.Dispose();
  }
}
public bool ThumbnailCallback() 
{
  return false;
}

更多關于asp.net相關內(nèi)容感興趣的讀者可查看本站專題:《asp.net字符串操作技巧匯總》、《asp.net操作XML技巧總結(jié)》、《asp.net操作json技巧總結(jié)》、《asp.net文件操作技巧匯總》、《asp.net ajax技巧總結(jié)專題》及《asp.net緩存操作技巧總結(jié)》。

希望本文所述對大家asp.net程序設計有所幫助。

相關文章

最新評論

望奎县| 大渡口区| 天门市| 台州市| 水城县| 印江| 涞源县| 深水埗区| 洮南市| 麻城市| 白山市| 交口县| 永康市| 额济纳旗| 大洼县| 阳东县| 云霄县| 鄯善县| 延寿县| 石城县| 治县。| 巨野县| 盈江县| 河西区| 洞口县| 兴宁市| 綦江县| 烟台市| 密山市| 云龙县| 广西| 沾益县| 河间市| 永吉县| 游戏| 高陵县| 城口县| 宝山区| 玛纳斯县| 夏河县| 高平市|