类似windows explorer的图片浏览器
2007-10-07 16:49
218 查看
windows explore在查看文件中有查看缩略图这一选项,他的实质就是从thumbs文件中读取出已经生成的缩略图文件
然后做为image显示出来
在网上有如何读出thumbs文件的类库,今天使用这个类库模仿一下window explorer
类库的源地址
http://www.petedavis.net/MySite/DynPageView.aspx?pageid=31
原理读出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);
}
}
然后做为image显示出来
在网上有如何读出thumbs文件的类库,今天使用这个类库模仿一下window explorer
类库的源地址
http://www.petedavis.net/MySite/DynPageView.aspx?pageid=31
原理读出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);
}
}
相关文章推荐
- Clover3(可以让Windows Explorer像浏览器一样有标签页)
- 调Windows 7的图片浏览器查看图片
- Process Explorer windows 下的进程浏览器
- css实现跨浏览器的盒阴影效果告别图片实现类似效果
- JavaScript 类似flash效果的立体图片浏览器
- UIImageView 如何实现windows 桌面类似的背景壁纸屏幕(很小的图片会显示N多个)?
- css实现跨浏览器的box-shadow盒阴影效果告别图片实现类似效果(2)
- js 给div 添加选区,类似windows桌面选区一样,兼容ie6、7、8、9、10、Firefox、Google、所有浏览器
- iOS 类似朋友圈的图片浏览器SDPhotoBrowser
- 图片浏览器:利用UIScrollView做类似微信好友文件中的图片浏览器(缩放、单击退出、双击放大等)
- windows下打印图片出现explorer.exe错误的问题?
- Mac下的浏览器类似Windows中Ctrl+F5的不请求缓存刷新页面的快捷键
- 以缩略图的形式在Windows资源浏览器中显示自定义格式图片
- Windows 剪切板的应用——复制浏览器or本地目录图片
- 表单圆角大法(无JS无图片通杀所有浏览器)
- JS不同浏览器图片载入处理
- 在图片上显示左右箭头类似翻页的代码
- 让图片直线移动到鼠标点击位置,类似游戏里的人物走动!
- [SDK2.2]Windows Azure Storage (16) 使用WCF服务,将本地图片上传至Azure Storage (上) 客户端代码
- perl删除Windows下的图片缓存缩略图(Thumbs.db)