做个幻灯显示图片的程序

以前装了一段时间的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,设定好时间间隔就可以了。当然这个比较简陋,没有动画渐变双及其它功能,需要这些功能的就请各位兄弟自己去添加

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值