windows explore在檢視檔案中有檢視縮略圖這一選項,他的實質就是從thumbs檔案中讀取出已經生成的縮略圖檔案
然後做為image顯示出來
在網上有如何讀出thumbs檔案的類庫,今天使用這個類庫模仿一下window explorer
類庫的源位址
<a href="http://www.petedavis.net/mysite/dynpageview.aspx?pageid=31">http://www.petedavis.net/mysite/dynpageview.aspx?pageid=31</a>
原理讀出thumbs檔案中的圖像并生成一個picturebox數組,顯示圖像并放置到窗體上,在picturebox被單擊時,擊發一個事件
将原圖顯示出來
private string[] allfilename;
thumbdblib.thumbdb test;
private picturebox[] allimage;
private void button1_click(object sender, system.eventargs e)
...{
this.invalidate();
test=new thumbdb(this.textbox1.text);
allfilename=test.getthumbfiles();
allimage=new picturebox[allfilename.length];
int x=0,y=50;
int i=0;
foreach(string bb in allfilename)
...{
allimage[i]=new picturebox();
allimage[i].location=new point(x,y);
image gotimg=test.getthumbnailimage(bb);
x+=80;
if(x>this.width)
...{
x=0;
y+=80;
}
allimage[i].image=gotimg;
allimage[i].size=new size(75,75);
allimage[i].sizemode=pictureboxsizemode.stretchimage;
allimage[i].click+=new eventhandler(imagecontrol_click);
allimage[i].tag=bb;
this.controls.add(allimage[i]);
//this.refresh();
i++;
}
}
/**//// <summary>
/// 當使用者單擊時顯示大圖檔
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void imagecontrol_click(object sender, eventargs e)
form showbig=new form();
string filename=utitlity.getdirfromfilename(textbox1.text)+"/"+(sender as picturebox).tag;
picturebox pb=new picturebox();
bitmap showmap=new bitmap(filename);
pb.image=showmap;
pb.size=new size(showmap.width,showmap.height);
showbig.size=new size(showmap.width,showmap.height);
pb.location=new point(0,0);
showbig.controls.add(pb);
if(showbig.showdialog()==dialogresult.ok)
showbig.dispose();
}
public class utitlity
/**//// <summary>
/// 從檔案名中取出檔案路徑
/// </summary>
/// <param name="filename">檔案名</param>
/// <returns>檔案所在的路徑</returns>
public static string getdirfromfilename(string filename)
string[] allpart=filename.split('/');
return filename.replace(allpart[allpart.length-1],string.empty);