【问题标题】:Displaying an array of images in picturebox在图片框中显示图像数组
【发布时间】:2012-08-08 15:46:46
【问题描述】:

我是 Visual C# 的新手 我想在图片框中显示一组图像

这是我的代码:

string[] list = Directory.GetFiles(@"C:\\pictures", "*.jpg");

Image[] images = new Image[5];

for (int index = 0; index < 5; index++)
{
    images[index] = Image.FromFile(list[index]);
}

当我运行它时,图片框是空白的。

【问题讨论】:

标签: c# arrays image picturebox


【解决方案1】:

添加表单级变量:

private int selectedImageIndex = -1;   // to store the active index in the images array

添加一个带有点击事件处理程序的按钮:

selectedImageIndex++;  // increment the active index
// if the active index is equal to the image count we've gone past the end of the array, so loop back to the beginning.
if (images.Count == selectedImageIndex) { selectedImageIndex = 0; }
pictureBox.Image = images[selectedImageIndex];  // assign the selected image to the picturebox

【讨论】:

    猜你喜欢
    • 2012-08-05
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 2014-06-01
    • 1970-01-01
    • 2014-12-17
    • 2022-11-16
    相关资源
    最近更新 更多