using System; using System.Collections.Generic; using System.Text; using System.Drawing; using System.Text.RegularExpressions; namespace FastGallery { /// /// An image included in the gallery. /// [Serializable] class IncludedImage : ICloneable { /// /// Construct an image. /// /// The full path of the image filename on disk. public IncludedImage(string pathName) { this.originalPathName = pathName; this.name = System.IO.Path.GetFileName(pathName); this.location = System.IO.Path.GetDirectoryName(pathName); } private string originalPathName; /// /// The filename name. /// public string Name { get { return name; } set { if (!name.Equals(value)) { name = value; lastSavedAs = null; } } } private string name; /// /// The path of the image on disk. /// public string Location { get { return location; } set { location = value; } } private string location; /// /// Clone the IncludedImage object. /// public object Clone() { IncludedImage includedImage = (IncludedImage)MemberwiseClone(); return includedImage; } /// /// The number of clockwise 90 degree rotations to apply to the image. /// public int Rotations { get { return rotations; } set { if (rotations != value) { rotations = value; lastSavedAs = null; } } } private int rotations = 0; /// /// Rotate the image clockwise by 90 degrees. /// public void RotateRight() { rotations++; if (rotations == 4) { rotations = 0; } lastSavedAs = null; } /// /// Rotate the image anticlockwise by 90 degrees. /// public void RotateLeft() { rotations--; if (rotations == -1) { rotations = 3; } lastSavedAs = null; } /// /// Get the bitmap object associated with the image. /// internal Bitmap GetBitmap() { Bitmap bitmap = (Bitmap)Image.FromFile(originalPathName); switch (rotations) { case 0: break; case 1: bitmap.RotateFlip(RotateFlipType.Rotate90FlipNone); break; case 2: bitmap.RotateFlip(RotateFlipType.Rotate180FlipNone); break; case 3: bitmap.RotateFlip(RotateFlipType.Rotate270FlipNone); break; } return bitmap; } /// /// The path of the main image used when it was last saved. /// /// This information is retained to reduce unnecessary rebuilding of the gallery. internal string LastSavedAs { get { return lastSavedAs; } set { lastSavedAs = value; } } private string lastSavedAs; /// /// The maximum width of the main image used when the image was last saved. /// /// This information is retained to reduce unnecessary rebuilding of the gallery. internal int LastSaveAsMaxWidth { get { return lastSaveAsMaxWidth; } set { lastSaveAsMaxWidth = value; } } private int lastSaveAsMaxWidth; /// /// The disk path of the thumbnail image when last saved. /// /// This information is retained to reduce unnecessary rebuilding of the gallery. internal string LastSavedAsThumbnail { get { return lastSavedAsThumbnail; } set { lastSavedAsThumbnail = value; } } private string lastSavedAsThumbnail; /// /// The thumbnail size (average edge dimensions) used when the image was last saved. /// /// This information is retained to reduce unnecessary rebuilding of the gallery. internal int LastSavedAsThumbnailSize { get { return lastSavedAsThumbnailSize; } set { lastSavedAsThumbnailSize = value; } } private int lastSavedAsThumbnailSize; /// /// The rotations to the main image used when this image was last saved. /// /// This information is retained to reduce unnecessary rebuilding of the gallery. internal int LastSaveWithRotations { get { return lastSaveWithRotations; } set { lastSaveWithRotations = value; } } private int lastSaveWithRotations; /// /// The rotations to the thumbnail used when this image was last saved. /// /// This information is retained to reduce unnecessary rebuilding of the gallery. internal int LastSaveWithRotationsThumbnail { get { return lastSaveWithRotationsThumbnail; } set { lastSaveWithRotationsThumbnail = value; } } private int lastSaveWithRotationsThumbnail; } }