做个幻灯显示图片的程序
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,设定好时间间隔就可以了。当然这个比较简陋,没有动画渐变双及其它功能,需要这些功能的就请各位兄弟自己去添加
当然首先放置一个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,设定好时间间隔就可以了。当然这个比较简陋,没有动画渐变双及其它功能,需要这些功能的就请各位兄弟自己去添加
相关文章推荐
- 做个幻灯显示图片的程序。
- 在JSP程序中我用新图片替换掉了原图片(名字,格式相同),为什么打开网页显示的还是以前的图片呢
- py2exe 打包 pyqt程序的图片(ico等) 不显示的问题
- 2440裸机程序——LCD图片显示实验
- 微信小程序image组件binderror使用例子(对应html、js中的onerror) ,图片失效显示默认图片
- 用PHP程序实现随机广告图片显示
- 关于iReport制作报表在程序中导出html时的图片显示问题
- universal-image-loader加载图片,程序异常崩溃,图片不在加载显示问题
- 微信小程序image图片自适应宽度比例显示的方法
- 小程序image无法显示图片,src地址正确也一片空白显示不了
- 小程序图片加载不出来(显示)
- Android 在程序界面上显示图片
- VS2008中添加程序启动时显示图片功能方法
- 基于s3c2440 lcd framebuffer 320x240 驱动 测试 显示 320x240 16bpp bmp 图片测试程序
- 微信小程序image图片自适应宽度比例显示的方法
- WinForm版ListView图片查看小程序(用ListView显示某个文件夹中图片为缩略图,PictureBox显示大图)
- 在Android程序里显示自己的图片
- x64 win7系统下VS2010运行显示图片程序,出现错误:fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- 编译好的QT程序在其他没有安装QT的机器上会出现图标和图片无法正常显示的问题。
- 一个图片轮换显示程序[源创]