C#新人,请教各位大神图片显示问题! 想法:让某个目录下的图片在Picturebox中每隔5秒显示一张。控件:picturebox,imagelist,timer结果:显示出来的是很小很小的图标,改了下imagelist里面的图像大小,最大也是256,显示出来的根本不是原图大小。咱是个年纪大的新手,最好大师们能麻烦下,能否提供源码让咱学习下。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我是看百度上说的,要连续显示图片要imagelist和picturebox合起来用 using System;using System.Collections.Generic;using System.Windows.Forms;using System.IO;using System.Drawing;namespace Demo{ public partial class Form1 : Form { ImagePlayer player = null; public Form1() { InitializeComponent(); player = new ImagePlayer(pictureBox1, "pic"); player.Interval = 5000; } private void button1_Click(object sender, EventArgs e) { player.Play(); } private void button2_Click(object sender, EventArgs e) { player.Stop(); } } public interface IPlayer { void Play(); void Stop(); } public class ImagePlayer : IPlayer { private readonly string[] EXTENSIONS = { "bmp", "jpg", "jpeg", "png", "gif" }; private IList<Image> images; private PictureBox canvas; private int frameIndex; private System.Windows.Forms.Timer timer; public int Interval { get { return this.timer.Interval; } set { this.timer.Interval = value; } } public ImagePlayer(PictureBox canvas, string directoryName) { this.timer = new Timer(); this.timer.Interval = 1000; this.timer.Tick += new EventHandler(timer_Tick); this.LoadImages(directoryName); this.canvas = canvas; this.frameIndex = 0; if (images.Count > 0) { this.canvas.Image = images[0]; } } private void timer_Tick(object sender, EventArgs e) { canvas.Image = images[(frameIndex++) % images.Count]; } private void LoadImages(string directoryName) { if (!Directory.Exists(directoryName)) throw new FileNotFoundException(); try { this.images = new List<Image>(); DirectoryInfo dirinfo = new DirectoryInfo(directoryName); FileInfo[] files = dirinfo.GetFiles(); for (int i = 0; i < files.Length; i++) { foreach (string ext in EXTENSIONS) { if (files[i].Extension == "." + ext) { Image image = Image.FromFile(files[i].FullName); this.images.Add(image); break; } } } } catch (FileNotFoundException e) { throw e; } } public void Play() { this.timer.Start(); } public void Stop() { this.timer.Stop(); } }} public void Play(){ if(images.Count==0) return; this.timer.Start();} 这是什么错误啊 .net 发送邮件问题! 用linq to sql的时候有没有,先设计linq类然后再设计数据库的做法。 我的系统进程里出现了netsend.exe进程 SESSION值过期报错该如何解决?? 小弟的问题非常简单,先来先的分 把一个StatusBar定义在一个静态变量里面,如何在主窗体中加载这个控件?救急啊……………… 还是关于panel上图像保存的问题,很着急,急着交作业,高人指点一下 C#程序提供的接口如何封装才能使别的语言也能来调用? 大家从哪里学的水晶报表? 请教INotifyPropertyChanged问题 求推荐好的C#书籍
我是看百度上说的,要连续显示图片要imagelist和picturebox合起来用
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.IO;
using System.Drawing;
namespace Demo
{
public partial class Form1 : Form
{
ImagePlayer player = null;
public Form1()
{
InitializeComponent(); player = new ImagePlayer(pictureBox1, "pic");
player.Interval = 5000;
}
private void button1_Click(object sender, EventArgs e)
{
player.Play();
}
private void button2_Click(object sender, EventArgs e)
{
player.Stop();
}
} public interface IPlayer
{
void Play();
void Stop();
} public class ImagePlayer : IPlayer
{
private readonly string[] EXTENSIONS = { "bmp", "jpg", "jpeg", "png", "gif" };
private IList<Image> images;
private PictureBox canvas;
private int frameIndex;
private System.Windows.Forms.Timer timer; public int Interval
{
get { return this.timer.Interval; }
set { this.timer.Interval = value; }
} public ImagePlayer(PictureBox canvas, string directoryName)
{
this.timer = new Timer();
this.timer.Interval = 1000;
this.timer.Tick += new EventHandler(timer_Tick); this.LoadImages(directoryName); this.canvas = canvas;
this.frameIndex = 0; if (images.Count > 0)
{
this.canvas.Image = images[0];
}
} private void timer_Tick(object sender, EventArgs e)
{
canvas.Image = images[(frameIndex++) % images.Count];
} private void LoadImages(string directoryName)
{
if (!Directory.Exists(directoryName))
throw new FileNotFoundException();
try
{
this.images = new List<Image>();
DirectoryInfo dirinfo = new DirectoryInfo(directoryName);
FileInfo[] files = dirinfo.GetFiles();
for (int i = 0; i < files.Length; i++)
{
foreach (string ext in EXTENSIONS)
{
if (files[i].Extension == "." + ext)
{
Image image = Image.FromFile(files[i].FullName);
this.images.Add(image);
break;
}
}
}
}
catch (FileNotFoundException e)
{
throw e;
}
} public void Play()
{
this.timer.Start();
} public void Stop()
{
this.timer.Stop();
}
}
}
public void Play()
{
if(images.Count==0) return;
this.timer.Start();
}