C#如何实现图片的下一张
用看图软件看图时,在一个文件夹里无论图片按什么排,也无论图片名字是什么,他都能按顺序从第张开始一直下去,谁能告诉我怎么用C#实现这个功能能不能说清楚点,我刚学对文件处理还...
用看图软件看图时,在一个文件夹里无论图片按什么排,也无论图片名字是什么,他都能按顺序从第张开始一直下去,谁能告诉我怎么用C#实现这个功能
能不能说清楚点,我刚学对文件处理还不是很熟 展开
能不能说清楚点,我刚学对文件处理还不是很熟 展开
3个回答
展开全部
//虽然无法完全满足你的需求...
private int IndexPicture = 1;
private int MaxLength = 0;
private string[] Picturename =null;
/// <summary>
/// 打开文件对话框选择图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click(object sender, System.EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "JPEG(*.jpg)|*.jpg|BMP(*.Bmp)|*.bmp|GIF(*.gif)|*.gif|所有文件(*.*)|*.*";
dlg.Multiselect = true;
IndexPicture = 1;
if (dlg.ShowDialog() == DialogResult.OK)
{
Picturename = new string[dlg.FileNames.Length+1];
for (int i = 0; i < dlg.FileNames.Length; i++)
{
MaxLength = dlg.FileNames.Length + 1;
Picturename[i] = dlg.FileNames[i].ToString();
}
}
Picturename[MaxLength-1] = Picturename[0];
pictureBox1.Image=System.Drawing.Image.FromFile(Picturename[1]);
}
/// <summary>
/// 向后翻滚
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, System.EventArgs e)
{
if (IndexPicture < MaxLength-1)
{
IndexPicture = IndexPicture + 1;
pictureBox1.Image=System.Drawing.Image.FromFile(Picturename[IndexPicture]);
}
else
{
MessageBox.Show("已到最后一张图片");
}
}
/// <summary>
/// 重置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, System.EventArgs e)
{
pictureBox1.Image=System.Drawing.Image.FromFile(Picturename[1]);
IndexPicture = 1;
}
private int IndexPicture = 1;
private int MaxLength = 0;
private string[] Picturename =null;
/// <summary>
/// 打开文件对话框选择图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click(object sender, System.EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "JPEG(*.jpg)|*.jpg|BMP(*.Bmp)|*.bmp|GIF(*.gif)|*.gif|所有文件(*.*)|*.*";
dlg.Multiselect = true;
IndexPicture = 1;
if (dlg.ShowDialog() == DialogResult.OK)
{
Picturename = new string[dlg.FileNames.Length+1];
for (int i = 0; i < dlg.FileNames.Length; i++)
{
MaxLength = dlg.FileNames.Length + 1;
Picturename[i] = dlg.FileNames[i].ToString();
}
}
Picturename[MaxLength-1] = Picturename[0];
pictureBox1.Image=System.Drawing.Image.FromFile(Picturename[1]);
}
/// <summary>
/// 向后翻滚
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, System.EventArgs e)
{
if (IndexPicture < MaxLength-1)
{
IndexPicture = IndexPicture + 1;
pictureBox1.Image=System.Drawing.Image.FromFile(Picturename[IndexPicture]);
}
else
{
MessageBox.Show("已到最后一张图片");
}
}
/// <summary>
/// 重置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, System.EventArgs e)
{
pictureBox1.Image=System.Drawing.Image.FromFile(Picturename[1]);
IndexPicture = 1;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
string path = "D:/";
string[] fileNames = Directory.GetFiles(path);
foreach (string str in fileNames)
{
Image image = Image.FromFile(str);
if (image == null)
break;
//加上你自已的处理代码,比如要显示在界面上
}
string[] fileNames = Directory.GetFiles(path);
foreach (string str in fileNames)
{
Image image = Image.FromFile(str);
if (image == null)
break;
//加上你自已的处理代码,比如要显示在界面上
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
FileInfo循环一个DirectoryInfo下的所有文件
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询