Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17514 was 16995, checked in by gkronber, 6 years ago

#2520 Update plugin dependencies and references for HL.FLA for new persistence

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