[7128] | 1 | using System;
|
---|
| 2 | using System.Drawing;
|
---|
| 3 | using System.Drawing.Imaging;
|
---|
| 4 | using HeuristicLab.Common;
|
---|
| 5 | using HeuristicLab.Core;
|
---|
[16573] | 6 | using HEAL.Attic;
|
---|
[7128] | 7 |
|
---|
| 8 | namespace HeuristicLab.Analysis.FitnessLandscape.BoxCharts {
|
---|
| 9 |
|
---|
[16573] | 10 | [StorableType("58401951-FA4A-4D64-87DD-0B42DC00991F")]
|
---|
[7128] | 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]
|
---|
[16573] | 35 | protected BitmapItem(StorableConstructorFlag _) : base(_) { }
|
---|
[7128] | 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 | }
|
---|