Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/SharpVectorRuntime/EmbeddedBitmapDataConverter.cs @ 12806

Last change on this file since 12806 was 12762, checked in by aballeit, 9 years ago

#2283 GUI updates, Tree-chart, MCTS Version 2 (prune leaves)

File size: 1.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.IO;
5using System.Reflection;
6using System.Text;
7
8namespace SharpVectors.Runtime
9{
10    public sealed class EmbeddedBitmapDataConverter : TypeConverter
11    {
12        #region Constructors and Destructor
13
14        public EmbeddedBitmapDataConverter()
15        {   
16        }
17
18        #endregion
19
20        #region Public Methods
21
22        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
23        {
24            return sourceType == typeof( string );
25
26        }
27
28        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
29        {
30            if( destinationType == typeof( string ) )
31            {
32                return true;
33            }
34            return base.CanConvertTo( context, destinationType );
35        }
36
37        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
38        {
39            byte[] toDecode = Convert.FromBase64String((string)value);
40
41            MemoryStream memoryStream = new MemoryStream(toDecode);
42            return new EmbeddedBitmapData(memoryStream);
43        }
44
45        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
46        {
47            if( destinationType == typeof(string))
48            {
49                EmbeddedBitmapData bitmapInfo = (EmbeddedBitmapData)value;
50                MemoryStream memoryStream = bitmapInfo.Stream;
51
52                return Convert.ToBase64String(memoryStream.ToArray());
53           }
54
55            return base.ConvertTo( context, culture, value, destinationType );
56        }
57       
58        #endregion Methods
59    }
60}
Note: See TracBrowser for help on using the repository browser.