1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Drawing;
|
---|
24 | using System.Drawing.Imaging;
|
---|
25 | using System.IO;
|
---|
26 | using System.Linq;
|
---|
27 | using Google.Protobuf;
|
---|
28 | using HEAL.Attic;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Persistence {
|
---|
31 | [Transformer("D0ADB806-2DFD-459D-B5DA-14B5F1152534", 404)]
|
---|
32 | [StorableType("B13D6153-E71D-4B76-9893-81D3570403E8")]
|
---|
33 | internal sealed class BitmapTransformer : BoxTransformer<Bitmap> {
|
---|
34 | protected override void Populate(Box box, Bitmap value, Mapper mapper) {
|
---|
35 | lock (value)
|
---|
36 | using (var ms = new MemoryStream()) {
|
---|
37 | value.Save(ms, ImageFormat.Png);
|
---|
38 | box.Bytes = ByteString.CopyFrom(ms.ToArray());
|
---|
39 | }
|
---|
40 | }
|
---|
41 |
|
---|
42 | protected override Bitmap Extract(Box box, Type type, Mapper mapper) {
|
---|
43 | using (var ms = new MemoryStream()) {
|
---|
44 | ms.Write(box.Bytes.ToArray(), 0, box.Bytes.Length);
|
---|
45 | ms.Seek(0, SeekOrigin.Begin);
|
---|
46 | return new Bitmap(ms);
|
---|
47 | }
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|