Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/BoxChart/BitmapItem.cs @ 16577

Last change on this file since 16577 was 16573, checked in by gkronber, 5 years ago

#2520: changed HeuristicLab.FLA addon to compile with new HL.Persistence

File size: 1.8 KB
Line 
1using System;
2using System.Drawing;
3using System.Drawing.Imaging;
4using HeuristicLab.Common;
5using HeuristicLab.Core;
6using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
7using HEAL.Attic;
8
9namespace HeuristicLab.Analysis.FitnessLandscape.BoxCharts {
10
11  [StorableType("58401951-FA4A-4D64-87DD-0B42DC00991F")]
12  public class BitmapItem : Item {
13
14    [Storable]
15    private Bitmap image;
16
17    public Bitmap Image {
18      get { return image; }
19      set {
20        if (value == image)
21          return;
22        image = value;
23        OnImageChanged();
24      }
25    }
26
27    public event EventHandler ImageChanged;
28
29    protected virtual void OnImageChanged() {
30      EventHandler handler = ImageChanged;
31      if (handler != null)
32        handler(this, EventArgs.Empty);
33    }
34
35    [StorableConstructor]
36    protected BitmapItem(StorableConstructorFlag _) : base(_) { }
37    protected BitmapItem(BitmapItem original, Cloner cloner) : base(original, cloner) {
38      Image = (Bitmap)original.Image.Clone();
39    }
40
41    public BitmapItem(Bitmap image) {
42      Image = image;
43    }
44
45    public override IDeepCloneable Clone(Cloner cloner) {
46      return new BitmapItem(this, cloner);
47    }
48
49    public virtual void Save(string filename) {
50      if (image == null)
51        return;
52      var format = ImageFormat.Png;
53      if (filename.Length >=3) {
54        switch(filename.Substring(filename.Length-4, 3).ToLower()) {
55          case "jpg": format = ImageFormat.Jpeg; break;
56          case "emf": format = ImageFormat.Emf; break;
57          case "gif": format = ImageFormat.Gif; break;
58          case "tif": format = ImageFormat.Tiff; break;
59          default: format = ImageFormat.Png; break;
60        }
61      }
62      image.Save(filename, format);
63    }
64
65  }
66}
Note: See TracBrowser for help on using the repository browser.