C
C#3mo ago
armoiredu44

can't find an image that is asked to be searched

so I've got this code that select a random image
private static Random rand = new Random();
private void SetRandomBackgroundImage()
{
string[] backgrounds = {
"0.png", "1.png", "2.png", "3.png", "4.png", "5.png", "6.png", "7.png",
"8.png", "9.png", "10.png", "11.png", "12.png", "13.png", "14.png",
"15.png", "16.png", "17.png", "18.png", "19.png", "20.png", "21.png",
"22.png", "23.png", "24.png", "25.png", "26.png", "27.png", "28.png",
"29.png", "30.png", "31.png", "32.png", "33.png", "34.png", "35.png",
"36.png", "37.png"
};

int index = rand.Next(backgrounds.Length);
string selectedImage = backgrounds[index];
string imagePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, selectedImage);

if (File.Exists(imagePath))
{
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.UriSource = new Uri(imagePath, UriKind.Absolute);
bitmap.EndInit();
BackgroundImage.Source = bitmap;
}
else
{
MessageBox.Show($"Image not found: {imagePath}");
}
}
private static Random rand = new Random();
private void SetRandomBackgroundImage()
{
string[] backgrounds = {
"0.png", "1.png", "2.png", "3.png", "4.png", "5.png", "6.png", "7.png",
"8.png", "9.png", "10.png", "11.png", "12.png", "13.png", "14.png",
"15.png", "16.png", "17.png", "18.png", "19.png", "20.png", "21.png",
"22.png", "23.png", "24.png", "25.png", "26.png", "27.png", "28.png",
"29.png", "30.png", "31.png", "32.png", "33.png", "34.png", "35.png",
"36.png", "37.png"
};

int index = rand.Next(backgrounds.Length);
string selectedImage = backgrounds[index];
string imagePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, selectedImage);

if (File.Exists(imagePath))
{
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.UriSource = new Uri(imagePath, UriKind.Absolute);
bitmap.EndInit();
BackgroundImage.Source = bitmap;
}
else
{
MessageBox.Show($"Image not found: {imagePath}");
}
}
but it says an image that is not on the list is found???
No description
2 Replies
Jimmacle
Jimmacle3mo ago
well, is there an image in that folder with that name?
armoiredu44
armoiredu44OP3mo ago
No Lemme double check
Want results from more Discord servers?
Add your server