您的位置:首页 > 其它

做个幻灯显示图片的程序

2004-07-19 18:39 295 查看
以前装了一段时间的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,设定好时间间隔就可以了。当然这个比较简陋,没有动画渐变双及其它功能,需要这些功能的就请各位兄弟自己去添加
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐