using System; using System.Drawing; using System.Drawing.Imaging; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Analysis.FitnessLandscape.BoxCharts { [StorableClass] 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(bool deserializing) : base(deserializing) { } 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); } } }