using System; using System.Drawing; using System.Drawing.Imaging; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.IO; using System.Threading; namespace slideshow_0_4 { /// /// Slide Show 0.4 by Neil Moomey, www.neilmoomey.com, 9-17-04 /// I created this program for my photography club. We needed a simple and foolproof way to /// display images full screen at our meetings. The program launches a File Chooser. After /// you select the first image to display it goes to full screen mode with a black background /// and no border. I have found this program works great for my initial edit of images so I have /// added some features I find useful. Make sure your images are not protected if you wish to /// use the rotate and delete features. /// /// Arrow keys: Navigation /// Page Down/Up: Navigation /// Home: Go to first image /// End: Go to last image /// Space bar: Read detailed EXIF data /// F1: toggle on/off footer information. /// F2: Toggle on/off Auto-Rotate feature based on EXIF image orientation data /// Delete: Move file to a folder called _Delete /// c: Copy image to a folder called _Copy /// r: Rotate right and lossless save /// l: Rotate left and lossless save /// Esc: Exit the program. /// Note: Lossless rotation only if the width and height are both multiples of 16 pixels such as most digital /// cameras produce. See Microsoft .Net documentation for details /// Also the auto-rotate feature will only rotate an image from landscape to portrait orientation. This ensures it /// only rotates the image once. The EXIF orientation data is unaltered. /// public class Form1 : System.Windows.Forms.Form { /// /// Required designer variable. /// private System.ComponentModel.Container components = null; private System.Drawing.Size screenSize; private String currentFile; private int pointer; private ArrayList fileList; System.Collections.IEnumerator myEnumerator; String directoryName, directoryParent; private Button button; private bool panelFlag, footerFlag, rotateFlag; private float w,h; private ContextMenu popUpMenu; private MenuItem checkToggleFooter; private MenuItem checkToggleRotate; public Form1() { InitializeComponent(); FormBorderStyle = FormBorderStyle.None; pointer = 0; panelFlag=false; footerFlag=false; rotateFlag=false; currentFile=""; this.SuspendLayout(); //Menu menu = new Menu(); //System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof(Form1)); //this.Icon = (System.Drawing.Icon) resources.GetObject ("$this.Icon"); //System.Drawing.Icon ico = new System.Drawing.Icon("MISC41.ICO"); //this.Icon = ico; // What is screen size? (1024x768 most likely) use: screenSize.Width, screenSize.Height screenSize = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Size; this.AutoScaleBaseSize = new System.Drawing.Size(0, 0); this.ClientSize = new System.Drawing.Size(screenSize.Width, screenSize.Height); this.Name = "Slide Show"; this.ResumeLayout(false); // The first step is to open a File Chooser currentFile = this.BrowseOpen(); //String //Cursor.Hide(); try { fileList = GetFileList(currentFile); //ArrayList of Strings pointer = fileList.IndexOf(currentFile); // int of the image postion in the ArrayList Console.WriteLine("currentFile at startup = " + currentFile); Console.WriteLine("fileList[{0}]= {1}", pointer, fileList[pointer]); } catch (Exception e) { Console.WriteLine("This process failed: {0}", e.ToString()); Environment.Exit(-1); } this.KeyUp += new KeyEventHandler(keyHandler); AddMenu(); } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } // Draw Image to Screen. Forms.Control.OnPaint // Use Invalidate() to repaint. protected override void OnPaint(PaintEventArgs e) { int displayWidth,displayHeight,x,y; String text, fNumber, exposureTime, exposureBiasValue, ISO, focalLength; PointF drawPoint; Graphics g = e.Graphics; SolidBrush brush; Bitmap bmp; // Give focus to screen this.Activate(); currentFile=fileList[pointer].ToString(); // Auto rotate if the flag is on and it's a landscape image if (rotateFlag==true) { bmp = new Bitmap(currentFile); displayWidth=bmp.Width; displayHeight=bmp.Height; ExifReader r = new ExifReader(currentFile); String orientation = r.GetOrientation(); Console.WriteLine("Orientation: " + r.GetOrientation()); r.MyDispose(); // Release handle so we can rotate it bmp.Dispose(); // Release handle so we can rotate it if (displayWidth>displayHeight && orientation=="Rotate Right") RotateRight(); if (displayWidth>displayHeight && orientation=="Rotate Left") RotateLeft(); } bmp = new Bitmap(currentFile); displayWidth=bmp.Width; displayHeight=bmp.Height; // Must use float for h/w ratio because int will return 0 // Will use w, h later so make it a class variable w=bmp.Width; h=bmp.Height; System.Console.WriteLine("w1 = "+ displayWidth + " h1 = " + displayHeight); // Determine the width and height to display full screen if (bmp.Width*bmp.Height != 0) { if (bmp.Width> screenSize.Width) { displayHeight = (int)((h/w)*screenSize.Width); displayWidth=screenSize.Width; } if (displayHeight > screenSize.Height) { displayWidth = (int)((w/h)*screenSize.Height); displayHeight=screenSize.Height; } } System.Console.WriteLine("w2 = "+ displayWidth + " h2 = " + displayHeight); // Center image on screen x=0; y=0; if (displayWidth displayWidth) && (displayHeight > screenSize.Height - 40)) if ( ((float)displayHeight/(float)displayWidth) > 0.9 && screenSize.Width - displayWidth > 300 ) { text = ""; if (fNumber != "") text += "F" +fNumber + "\n"; if (exposureTime != "") text += exposureTime + "\n"; if (exposureBiasValue != "") text += exposureBiasValue + "\n"; if (ISO != "") text += "ISO" + ISO + "\n"; if (focalLength != "") text += focalLength + "mm\n"; text += Path.GetFileName(currentFile) + "\n"; drawPoint = new PointF(10F,(float)(screenSize.Height-205));//165 } else { // Horizontal EXIF images text = ""; if (fNumber != "") text += "F" +fNumber + ", "; if (exposureTime != "") text += exposureTime + ", "; if (exposureBiasValue != "") text += exposureBiasValue + ", "; if (ISO != "") text += "ISO" + ISO + ", "; if (focalLength != "") text += focalLength + "mm , "; text += Path.GetFileName(currentFile); drawPoint = new PointF(10F,(float)(screenSize.Height-40)); //PointF if (displayHeight > screenSize.Height - 40) brush = new SolidBrush(Color.White); } //Rectangle r3 = new Rectangle(0,displayHeight-10,displayWidth,40); if (displayHeight > screenSize.Height - 40) g.DrawString(text,new Font("Arial",22),brush,drawPoint); else g.DrawString(text,new Font("Arial",22),brush,drawPoint); r.MyDispose(); } // Release resources so we can delete file if we wish g.Dispose(); bmp.Dispose(); } public ArrayList GetFileList(String source) { String ext; int length; ArrayList imageNames = new ArrayList(); myEnumerator = imageNames.GetEnumerator(); DirectoryInfo directoryInfo = Directory.GetParent(source); directoryName = directoryInfo.FullName.ToString(); //String length=directoryName.LastIndexOf("\\"); directoryParent = directoryName.Substring(0,length); //String System.Console.WriteLine("directoryName = "+ directoryName); System.Console.WriteLine("directoryParent = "+ directoryParent); // Create an array representing the files in this directory. FileInfo[] fi = directoryInfo.GetFiles(); foreach (FileInfo fiTemp in fi) { //Console.WriteLine("ext = " + fiTemp.Extension); ext = fiTemp.Extension.ToLower(); if ((ext==".jpg") || (ext==".jpeg") || (ext==".gif") || (ext==".png") || (ext==".tif") || (ext==".tiff") || (ext==".bmp")) { imageNames.Add(fiTemp.FullName); Console.WriteLine("Name = " + fiTemp.FullName); } // Sort files in alphabetical order imageNames.Sort(); } return imageNames; } private String BrowseOpen() { // File Chooser to select the first image to be displayed OpenFileDialog fdlg = new OpenFileDialog(); fdlg.Title = "Please Select the First Image to Display." ; fdlg.Filter = "Image Files (JPEG,GIF,BMP,PNG,TIFF)|*.jpg;*.jpeg;*.gif;*.bmp;*.png;*.tif;*.tiff|JPEG Files(*.jpg;*.jpeg)|*.jpg;*.jpeg|GIF Files(*.gif)|*.gif|BMP Files(*.bmp)|*.bmp|PNG Files(*.png)|*.png|TIFF Files(*.tif;*tiff)|*.tif;*.tiff"; fdlg.FilterIndex = 1 ; //fdlg.RestoreDirectory = true ; if(fdlg.ShowDialog() == DialogResult.OK) { return fdlg.FileName; } else { return null; } } // Handle Key Events private void keyHandler(Object sender, KeyEventArgs e) { // Quit Program if ( e.KeyCode == Keys.Escape ) Quit(); // Advance to next image if ( e.KeyCode == Keys.Down || e.KeyCode == Keys.Right || e.KeyCode == Keys.PageDown) Next(); // Back up if ( e.KeyCode == Keys.Up || e.KeyCode == Keys.Left || e.KeyCode == Keys.PageUp) Prev(); // Jump to the beginning if ( e.KeyCode == Keys.Home ) Home(); // Jump to the end if ( e.KeyCode == Keys.End ) End(); // Jump 5 images at a time if ( e.KeyCode == Keys.NumPad5) Advance(5); // Toggle FooterFlag if ( e.KeyCode == Keys.F1 ) ToggleFooter(); // Toggle RotateFlag if ( e.KeyCode == Keys.F2 ) ToggleRotate(); // Move image to _Delete folder if ( e.KeyCode == Keys.Delete ) Delete(); // Copy file to _Copy folder if ( e.KeyCode == Keys.C ) Copy(); // Display Detailed EXIF data if ( e.KeyCode == Keys.Space ) DetailedEXIF(); //Test if ( e.KeyCode == Keys.RButton ) { MessageBox.Show("Hello"); Invalidate(); } // Rotate clockwise if ( e.KeyCode == Keys.R ) { RotateRight(); Invalidate(); } // Rotate counterclockwise if ( e.KeyCode == Keys.L ) { RotateLeft(); Invalidate(); } } private void button_Click (object sender, System.EventArgs e) { this.Controls.Remove(button); panelFlag=false; Invalidate(); } /// Functions for Key Events and Right Click Menu public void Quit() { if (panelFlag) { this.Controls.Remove(button); panelFlag=false; Invalidate(); } else Environment.Exit(-1); } public void Next() { //Console.WriteLine("Down1 Item =" + currentFile); if(pointer /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_Load(object sender, System.EventArgs e) { } } }