|
-
Feb 1st, 2008, 08:31 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Preload photos, then randomly show them
Hi,
I would like to preload 10-20 photos (200kB or so each) when the program starts so that I can randomly show them quicker later.
Please show me how to display them in picturebox, command button or maybe draw them on a form side by side. I need to be able to switch the pictures or move them around with a press of a button.
Tried the following code to load them, but don't know how to display them. Also let me know if there's a better way of doing this.
Code:
ImageList pics = new System.Windows.Forms.ImageList();
private void button1_Click(object sender, System.EventArgs e)
{
// Get all the picture files in the current directory.
string[] picFiles = Directory.GetFiles(Application.StartupPath, "*.jpg");
// Create an Image object for each file and add it to the ImageList.
foreach (string pic in picFiles)
{
Bitmap newB = new Bitmap(pic);
pics.Images.Add(newB);
}
}
-
Feb 1st, 2008, 08:56 AM
#2
Re: Preload photos, then randomly show them
Code:
private Image[] pictures;
private Random rng = new Random();
private void Form1_Load(object sender, EventArgs e)
{
string[] files = System.IO.Directory.GetFiles(Application.StartupPath, "*.jpg");
this.pictures = new Image[files.Length];
for (int index = 0; index < files.Length; index++)
{
this.pictures[index] = Image.FromFile(files[index]);
}
}
private void button1_Click(object sender, EventArgs e)
{
this.pictureBox1.Image = this.pictures[this.rng.Next(0, this.pictures.Length)];
}
Don't use an ImageList unless you have some specific use for an ImageList, like for a control that allows you to specify an ImageList and ImageIndex to select an Image, e.g. ListView or TreeView
-
Feb 1st, 2008, 09:04 AM
#3
Thread Starter
Hyperactive Member
Re: Preload photos, then randomly show them
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|