using System; using System.Drawing; using System.Drawing.Imaging; using HeuristicLab.Common; using HeuristicLab.Core; using HEAL.Attic; namespace HeuristicLab.Analysis.FitnessLandscape.BoxCharts { [StorableType("58401951-FA4A-4D64-87DD-0B42DC00991F")] public class BitmapItem : Item { [Storable] private Bitmap image; public Bitmap Image { get { return image; } set { if (value == image) return; image = value; OnImageChanged(); } } public event EventHandler ImageChanged; protected virtual void OnImageChanged() { EventHandler handler = ImageChanged; if (handler != null) handler(this, EventArgs.Empty); } [StorableConstructor] protected BitmapItem(StorableConstructorFlag _) : base(_) { } protected BitmapItem(BitmapItem original, Cloner cloner) : base(original, cloner) { Image = (Bitmap)original.Image.Clone(); } public BitmapItem(Bitmap image) { Image = image; } public override IDeepCloneable Clone(Cloner cloner) { return new BitmapItem(this, cloner); } public virtual void Save(string filename) { if (image == null) return; var format = ImageFormat.Png; if (filename.Length >=3) { switch(filename.Substring(filename.Length-4, 3).ToLower()) { case "jpg": format = ImageFormat.Jpeg; break; case "emf": format = ImageFormat.Emf; break; case "gif": format = ImageFormat.Gif; break; case "tif": format = ImageFormat.Tiff; break; default: format = ImageFormat.Png; break; } } image.Save(filename, format); } } }