adrianjohnson
Programmer
I'm trying to write a program which picks up an image at random. Here is some of the code:
It's the section marked "Set the image" where I need to be able to pick up the filename. I tried "Image.FromFile" but it doesn't recognise "FromFile" as it's a .net 2 statement.
Any ideas?
Thanks,
Adrian
Adrian Johnson
Code:
string nextImage = "";
int fileCount = 0;
// Get a count of images within the folder.
DirectoryInfo imageFiles = new DirectoryInfo(Properties.Settings.Default.ScreensaverImagePath);
// For each image extension (.jpg, .bmp, etc.)
foreach (string imageExtension in imageExtensions)
{
int imageCount = imageFiles.GetFiles(imageExtension).Length;
fileCount = fileCount + imageCount;
}
// Generate a random number.
Random random = new Random();
int randomNo = random.Next(fileCount);
for (int a = 0; a < fileCount; a++)
{
if (a == randomNo)
{
// Set the image.
}
}
return nextImage;
It's the section marked "Set the image" where I need to be able to pick up the filename. I tried "Image.FromFile" but it doesn't recognise "FromFile" as it's a .net 2 statement.
Any ideas?
Thanks,
Adrian
Adrian Johnson