/// <summary> /// Looks for a file path in the path list. If found and the path points to a file that exists, /// the image will be extracted from the file. /// </summary> /// <param name="nIndex">Specifies the index of the file path in the path list,</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="System.UnauthorizedAccessException"></exception> /// <exception cref="System.IO.IOException"></exception> /// <exception cref="System.Security.SecurityException"></exception> public Image GetImageFromIndex(int nIndex) { int nPathCount = m_sFilePaths.Count; string sFilePath = string.Empty; Image oImage = null; try { if ((nPathCount > 0) && (nIndex >= 0) && (nIndex < nPathCount)) { sFilePath = (string)m_sFilePaths[nIndex]; if (string.IsNullOrEmpty(sFilePath)) return null; FileInfo oFile = new FileInfo(sFilePath); if (oFile.Exists) { using (Image oImg = Image.FromFile(sFilePath)) { FileAttributes nAttributes = oFile.Attributes; // Update the ImageProperties member. m_oImageInfo = new ImageProperties(); m_oImageInfo.Archive = Convert.ToBoolean(nAttributes & FileAttributes.Archive); m_oImageInfo.Hidden = Convert.ToBoolean(nAttributes & FileAttributes.Hidden); m_oImageInfo.Normal = Convert.ToBoolean(nAttributes & FileAttributes.Normal); m_oImageInfo.ReadOnly = Convert.ToBoolean(nAttributes & FileAttributes.ReadOnly); m_oImageInfo.System = Convert.ToBoolean(nAttributes & FileAttributes.System); m_oImageInfo.Temporary = Convert.ToBoolean(nAttributes & FileAttributes.Temporary); m_oImageInfo.Frames = oImg.GetFrameCount(new FrameDimension(oImg.FrameDimensionsList[0])); m_oImageInfo.Dimensions = oImg.Size; m_oImageInfo.PixelFormat = oImg.PixelFormat; m_oImageInfo.Size = FileTools.ConvertBytes(oFile.Length); m_oImageInfo.Resolution = new Resolution(oImg.HorizontalResolution, oImg.VerticalResolution); m_oImageInfo.Name = oFile.Name; m_oImageInfo.Path = oFile.FullName; m_oImageInfo.Type = FileTools.GetFileExtensionDescription(oFile.Extension); m_oImageInfo.Accessed = oFile.LastAccessTime.ToShortDateString() + " - " + oFile.LastAccessTime.ToShortTimeString(); m_oImageInfo.Modified = oFile.LastWriteTime.ToShortDateString() + " - " + oFile.LastWriteTime.ToShortTimeString(); m_oImageInfo.Created = oFile.CreationTime.ToShortDateString() + " - " + oFile.CreationTime.ToShortTimeString(); m_oImageInfo.BitDepth = Bitmap.GetPixelFormatSize(oImg.PixelFormat); if (FileTools.IsExifFileType(oFile.Extension)) { ExifReader oExifReader = new ExifReader(oImg.PropertyItems); ExifImageProperties oExifInfo = new ExifImageProperties(m_oImageInfo); oExifInfo.Artist = oExifReader.GetExifProperty(PropertyItemID.Artist); oExifInfo.Title = oExifReader.GetExifProperty(PropertyItemID.ImageDescription); oExifInfo.Subject = oExifReader.GetExifProperty(PropertyItemID.XPSubject); oExifInfo.Comment = oExifReader.GetExifProperty(PropertyItemID.XPComment); oExifInfo.CameraMaker = oExifReader.GetExifProperty(PropertyItemID.EquipmentMake); oExifInfo.CameraModel = oExifReader.GetExifProperty(PropertyItemID.EquipmentModel); oExifInfo.Copyright = oExifReader.GetExifProperty(PropertyItemID.Copyright); oExifInfo.ExifVersion = oExifReader.GetExifProperty(PropertyItemID.ExifVersion); oExifInfo.DateTaken = oExifReader.GetExifProperty(PropertyItemID.DateTaken); oExifInfo.DateDigitized = oExifReader.GetExifProperty(PropertyItemID.DateDigitized); oExifInfo.Software = oExifReader.GetExifProperty(PropertyItemID.Software); oExifInfo.YCbCrSubSampling = oExifReader.GetExifProperty(PropertyItemID.YCbCrSubSampling); oExifInfo.YCbCrPositioning = oExifReader.GetExifProperty(PropertyItemID.YCbCrPositioning); oExifInfo.Orientation = oExifReader.GetExifProperty(PropertyItemID.Orientation); oExifInfo.ISOSpeed = oExifReader.GetExifProperty(PropertyItemID.ISOSpeed); oExifInfo.ExposureMode = oExifReader.GetExifProperty(PropertyItemID.ExposureMode); oExifInfo.ExposureProgram = oExifReader.GetExifProperty(PropertyItemID.ExposureProgram); oExifInfo.Flash = oExifReader.GetExifProperty(PropertyItemID.Flash); oExifInfo.MeteringMode = oExifReader.GetExifProperty(PropertyItemID.MeteringMode); oExifInfo.ColourSpace = oExifReader.GetExifProperty(PropertyItemID.ColorSpace); oExifInfo.ResolutionUnit = oExifReader.GetExifProperty(PropertyItemID.ResolutionUnit); oExifInfo.ComponentsConfiguration = oExifReader.GetExifProperty(PropertyItemID.ComponentsConfiguration); oExifInfo.Rating = oExifReader.GetExifProperty(PropertyItemID.Rating); oExifInfo.WhiteBalance = oExifReader.GetExifProperty(PropertyItemID.WhiteBalance); oExifInfo.SceneCaptureType = oExifReader.GetExifProperty(PropertyItemID.SceneCaptureType); oExifInfo.ExposureTime = oExifReader.GetExifProperty(PropertyItemID.ExposureTime); oExifInfo.FNumber = oExifReader.GetExifProperty(PropertyItemID.FNumber); oExifInfo.FocalLength = oExifReader.GetExifProperty(PropertyItemID.FocalLength); oExifInfo.MaxAperture = oExifReader.GetExifProperty(PropertyItemID.MaxAperture); oExifInfo.CompressedBitsPerPixel = oExifReader.GetExifProperty(PropertyItemID.CompressedBitsPerPixel); oExifInfo.ShutterSpeed = oExifReader.GetExifProperty(PropertyItemID.ShutterSpeed); oExifInfo.Compression = oExifReader.GetExifProperty(PropertyItemID.Compression); oExifInfo.PhotometricInterpretation = oExifReader.GetExifProperty(PropertyItemID.PhotometricInterpretation); oExifInfo.LightSource = oExifReader.GetExifProperty(PropertyItemID.LightSource); oExifInfo.Brightness = oExifReader.GetExifProperty(PropertyItemID.BrightnessValue); oExifInfo.Contrast = oExifReader.GetExifProperty(PropertyItemID.Contrast); oExifInfo.Saturation = oExifReader.GetExifProperty(PropertyItemID.Saturation); oExifInfo.Sharpness = oExifReader.GetExifProperty(PropertyItemID.Sharpness); m_oImageInfo = oExifInfo; } // Update field members. m_nSelectedIndex = nIndex; m_sSelectedFilePath = sFilePath; m_oPropertyItems = oImg.PropertyItems; // create a new bitmap from the image. oImage = new Bitmap(oImg, oImg.Size); } } else Remove(sFilePath); } } catch (OutOfMemoryException) { Remove(sFilePath); MessageBox.Show("Error trying to load image. (" + sFilePath + ")\n\nThe contents of this file could be damaged or corrupted.", "Load Image Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (ArgumentNullException e) { throw new ArgumentNullException(e.Message, e); } catch (UnauthorizedAccessException e) { throw new UnauthorizedAccessException(e.Message, e); } catch (IOException e) { throw new IOException(e.Message, e); } catch (System.Security.SecurityException e) { throw new System.Security.SecurityException(e.Message, e); } return oImage; }
/// <summary> /// Clears all the items in the image browser. /// </summary> public void Clear() { m_nFileCount = 0; m_nSelectedIndex = 0; m_sSelectedDirectoryPath = string.Empty; m_sSelectedFilePath = string.Empty; m_oImageInfo = null; m_oPropertyItems = null; // Clear the file path list. if (m_sFilePaths != null) m_sFilePaths.Clear(); // Clear the list view item list. if (m_oListViewItems != null) m_oListViewItems.Clear(); // Clear the image list. if (m_oImageList != null) m_oImageList.Images.Clear(); }
/// <summary> /// Creates a new instance of the PropertiesPanel class initialized with the specified parameters. /// </summary> /// <param name="oProperties"></param> public PropertiesPanel(ImageProperties oProperties) { InitializeComponent(); if (oProperties != null) { m_oProperties = oProperties; } else throw new ArgumentNullException("oProperties", "The specified parameter cannot be null."); }
/// <summary> /// Creates a new instace of the ExifImageProperties class initialized with the specified ImageProperties object. /// </summary> /// <param name="oImageProperties"></param> public ExifImageProperties(ImageProperties oImageProperties) { if (oImageProperties != null) { this.Accessed = oImageProperties.Accessed; this.Archive = oImageProperties.Archive; this.BitDepth = oImageProperties.BitDepth; this.Created = oImageProperties.Created; this.Dimensions = oImageProperties.Dimensions; this.Frames = oImageProperties.Frames; this.Hidden = oImageProperties.Hidden; this.Size = oImageProperties.Size; this.Modified = oImageProperties.Modified; this.Name = oImageProperties.Name; this.Normal = oImageProperties.Normal; this.Path = oImageProperties.Path; this.PixelFormat = oImageProperties.PixelFormat; this.ReadOnly = oImageProperties.ReadOnly; this.Resolution = oImageProperties.Resolution; this.System = oImageProperties.System; this.Temporary = oImageProperties.Temporary; this.Type = oImageProperties.Type; } }
/// <summary> /// Creates a new instance of the PropertiesPanel initialized with default values. /// </summary> public PropertiesPanel() { InitializeComponent(); m_oProperties = new ImageProperties(); }