以前装了一段时间的Longhorn,对slideBar的幻灯显示感觉到很漂亮。呵呵。现在我们自己用C#来实现他。
当然首先放置一个PictureBox在上面。还有一个对应的ContextMenu.里面有一项是选择图片目录。
程序如下:
private void LoadPictures(string path)
{
l.Clear(); //一个ArrayList
System.IO.DirectoryInfo d = new DirectoryInfo(path);
foreach(FileInfo f in d.GetFiles("*.jpg")) //这里只显示Jpeg图片
{
Image image = Image.FromFile(f.FullName);
float w = image.PhysicalDimension.Width;
float h = image.PhysicalDimension.Height;
float nw = 0;
float nh = 0;
if(w>h)
{
nw = this.pictureBox1.Width;
nh = h/w*nw;
}
else
{
nh = this.pictureBox1.Height;
nw = w/h*nh;
}
//生成适应于pictureBox大小的缩略图 try
{
l.Add(image.GetThumbnailImage((int)nw,(int)nh,null,new IntPtr()));
//l.Add(nImage);
}
finally
{
image.Dispose();
}
Application.DoEvents();
}
if(l.Count>0)
this.timer1.Enabled=true;
}
private Image ReturnPhoto(byte[] streamByte)
{
System.IO.MemoryStream stream = new System.IO.MemoryStream(streamByte, true);
stream.Write(streamByte, 0, streamByte.Length);
Bitmap bmp = new Bitmap(stream);
System.Drawing.Image image = bmp;//得到原图
//创建指定大小的图
System.Drawing.Image newImage = image.GetThumbnailImage(112, 136, null, new IntPtr());
Graphics g=Graphics.FromImage(newImage);
g.DrawImage(newImage,10,10, newImage.Width, newImage.Height); //将原图画到指定的图上
g.Dispose();
stream.Close();
return newImage;
}
bool ThumbnailCallback()
{
return true;
}
需要一个timer,设定好时间间隔就可以了。当然这个比较简陋,没有动画渐变双及其它功能,需要这些功能的就请各位兄弟自己去添加
本文介绍使用C#实现图片幻灯显示功能。首先需放置PictureBox和ContextMenu,通过选择图片目录加载图片。给出了加载图片和返回缩略图的程序代码,还提到需设置timer控制显示间隔,不过该程序较为简陋,部分功能需自行添加。
882

被折叠的 条评论
为什么被折叠?



