Free cookie consent management tool by TermsFeed Policy Generator

source: branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/BoxChart/BitmapItem.cs @ 8694

Last change on this file since 8694 was 7128, checked in by epitzer, 13 years ago

#1696 Integrate fitness landscape analysis plugins from Heureka! repository.

File size: 1.7 KB
RevLine 
[7128]1using System;
2using System.Drawing;
3using System.Drawing.Imaging;
4using HeuristicLab.Common;
5using HeuristicLab.Core;
6using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
7
8namespace HeuristicLab.Analysis.FitnessLandscape.BoxCharts {
9
10  [StorableClass]
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(bool deserializing) : base(deserializing) { }
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.