欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#縮略圖多路徑多格式保存的實(shí)例

 更新時(shí)間:2013年07月23日 10:22:35   作者:  
這篇文章介紹了C#縮略圖多路徑多格式保存的實(shí)例,有需要的朋友可以參考一下
復(fù)制代碼 代碼如下:

using System;
using System.Drawing;
namespace PubLib
{
 /// <summary>
 /// PicShow 的摘要說明。
 /// </summary>
 public class PicShow
 {
  public PicShow()
  {
   //
   // TODO: 在此處添加構(gòu)造函數(shù)邏輯
   //
  }
  //查找圖片文件是否存在
  public static string ViewPIC(string PicPath, string PicName)
  {
   string BigPic = Checks.HM_PHYSICSROOT + "MoviePIC/"+Checks.HM_PICROOTPATH+"/"+PicName;
   string SmlPic = Checks.HM_PHYSICSROOT + "MoviePIC/"+PicPath+"/"+PicName;
   if (null==PicName || false==System.IO.File.Exists(BigPic)) //大圖名稱為空或文件不存在
    PicName = "nopic.jpg";
   string OutPic = "MoviePIC/"+PicPath+"/"+PicName;
   if (!System.IO.File.Exists(SmlPic)) //查找小圖不存在
   {
    CreatePIC(PicPath, PicName);
    return OutPic;
   }
   return OutPic;
  }
  //創(chuàng)建縮略圖
  public static void CreatePIC(string PicPath, string PicName)
  {
   int iWidth,iHeight;
   if (null!=PicPath && PicPath.IndexOf("X")>1)
   {
    char[] spliter = {X};
    string[] aPicPath = PicPath.Split(spliter,2);
    iWidth  = Int32.Parse(aPicPath[0]);
    iHeight = Int32.Parse(aPicPath[1]);
    string BigPic = Checks.HM_PHYSICSROOT + "MoviePIC/"+Checks.HM_PICROOTPATH+"/"+PicName;
    string SmlPic = Checks.HM_PHYSICSROOT + "MoviePIC/"+PicPath+"/"+PicName;
    Image BigImage = Image.FromFile(BigPic);
    Image SmlImage = BigImage.GetThumbnailImage(iWidth,iHeight,null,new System.IntPtr());
    SmlImage.Save(SmlPic,System.Drawing.Imaging.ImageFormat.Jpeg);
    BigImage.Dispose();
    SmlImage.Dispose();
   }
  }
 }
}

Checks.HM_PHYSICSROOT 是一個(gè)靜態(tài)變量是系統(tǒng)的根路徑,你問怎么獲得?其實(shí)很簡單你可以直接寫個(gè)路徑給它。雖然不靈活但也還算簡單。我是這么搞的
public static string HM_PHYSICSROOT   = AppDomain.CurrentDomain.BaseDirectory;
(其實(shí)也簡單顧弄玄虛:~)
多路徑,也就是說的有點(diǎn)嚇人而已,你在生成縮略圖的時(shí)候指定一個(gè)路徑就可以了。就是這個(gè)參數(shù)PicPath是要你手工指定的,多格式說白了就是大小可以調(diào)整。我的方法是路徑就是大小,比如200*300的圖片路徑就叫200X300嘿嘿,當(dāng)然要指定一個(gè)圖片原始路徑,不然從那里得到圖片來生成縮略啊。這個(gè)Checks.HM_PICROOTPATH就只能手寫了,沒什么辦法。反正一次寫了以后也不改動(dòng)了。

相關(guān)文章

最新評論