The University of Tennessee at Martin
Department of Computer Science and Information Systems

Bob Bradley’s CS 490 - Special Topics - Windows Programming with C# and .Net

Project #2 & #3 – SlideShow Viewer & Thumbnailer



Using C# and the .Net framework, create the programs as outlined below:






Hints and Code Snippits


For the slideshow program:

Use a picture box control for the slideshow program.
The picture box control has an Image property.
To load an image, use code like this:

pictureBox1.Image = Image.FromFile(“pict.jpg”);

To prevent this code form crashing your program on a bad picture, wrap a try/catch around it.


Make a function called choose pictures.
To choose the pictures, use an OpenFileDialog.
Use code similar to the following:

of.Multiselect = true;
if (of.ShowDialog() == DialogResult.OK)
m_filenames = of.FileNames;


Make a function called NextPicture that displays the next picture from the filenames array.
Have the nextPicture function called from a button click or timer.


For the thumbnailer program:

This code will write to a text file:

StreamWriter sw3 = new StreamWriter(filename);
sw3.WriteLine("<html><head><title>Pictures</title></head>Blablabla...");
sw3.Close();

Use this code to create a directory:

if (!System.IO.Directory.Exists(dirname))
System.IO.Directory.CreateDirectory(dirname);

To save a picture:

img.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);

The html code that your program will need to generate for each picture is:

<a href="pict1.jpg" img src="thumbnails/pict1.jpg">

To generate the actuall thumbnail, use the sample code given in the MSDN help files, by pressing F1 on an image.GetThumbnailImage method.

 

Code for calculating file and path names:

String oldfilepath = @"c:\monkeys\picture.jpg";

String oldpath = System.IO.Path.GetDirectoryName(oldfilepath);
String oldname = System.IO.Path.GetFileName(oldfilepath);

String newpath = System.IO.Path.Combine(oldpath,"thumbnails");
String newfilepath = System.IO.Path.Combine(newpath,oldname);

MessageBox.Show(newfilepath);

// newfilepath will now be c:\monkeys\thumbnails\picture.jpg


Sameple output of the thumbnailer can be seen below: