Last change
on this file since 16482 was
16482,
checked in by gkronber, 5 years ago
|
#2520: added two custom transformers (for Fonts and Bitmaps) and registered types that are available in .NET Framework but not in .NET Standard 2.0 and added.
|
File size:
930 bytes
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Drawing;
|
---|
3 | using System.Drawing.Imaging;
|
---|
4 | using System.IO;
|
---|
5 | using System.Linq;
|
---|
6 | using Google.Protobuf;
|
---|
7 | using HEAL.Fossil;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.Persistence {
|
---|
10 | [Transformer("D0ADB806-2DFD-459D-B5DA-14B5F1152534", 404)]
|
---|
11 | [StorableType("B13D6153-E71D-4B76-9893-81D3570403E8")]
|
---|
12 | internal sealed class BitmapTransformer : BoxTransformer<Bitmap> {
|
---|
13 | protected override void Populate(Box box, Bitmap value, Mapper mapper) {
|
---|
14 | lock (value)
|
---|
15 | using (var ms = new MemoryStream()) {
|
---|
16 | value.Save(ms, ImageFormat.Png);
|
---|
17 | box.Bytes = ByteString.CopyFrom(ms.ToArray());
|
---|
18 | }
|
---|
19 | }
|
---|
20 |
|
---|
21 | protected override Bitmap Extract(Box box, Type type, Mapper mapper) {
|
---|
22 | using (var ms = new MemoryStream()) {
|
---|
23 | ms.Write(box.Bytes.ToArray(), 0, box.Bytes.Length);
|
---|
24 | ms.Seek(0, SeekOrigin.Begin);
|
---|
25 | return new Bitmap(ms);
|
---|
26 | }
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.