如何填充图像数组?

时间:2015-07-07 10:03:14

标签: c#

我有两个相似的代码来填充图像数组。这个有效:

for (int i = 0; i < num_of_slides; i++) //populate an array to hold original size images for each slide
{
        var fileName = @dir + (i + 1) + ".png";
        var bitmap = new BitmapImage(new Uri(fileName)); //{ /*.. more bitmap image options if you like .. */ };
        Image image = new Image() { Source = bitmap /*.. more image options ..*/ };

        image_array[i] = image;
}

但是这个:

for (int i = 0; i < 4; i++) //populate an array to hold original size images for each slide
{    
        var fileName = @"/Images/"+i+".jpg";
        var bitmap = new BitmapImage(new Uri(fileName, UriKind.Relative)); //{ /*.. more bitmap image options if you like .. */ };
        Image studio_image = new Image() { Source = bitmap /*.. more image options ..*/ };

        custom_studio_images[i] = studio_image;    
}

custom_studio_images[i] = studio_image;

崩溃

说它没有设置为对象的实例。我将不胜感激任何帮助或建议。

0 个答案:

没有答案