2 // System.Drawing.ImageFormatConverter.cs
5 // Dennis Hayes (dennish@Raytek.com)
6 // Sanjay Gupta (gsanjay@novell.com)
8 // (C) 2002 Ximian, Inc
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System.ComponentModel;
36 using System.Globalization;
37 using System.Drawing.Imaging;
38 using System.ComponentModel.Design.Serialization;
39 using System.Reflection;
41 namespace System.Drawing
44 /// Summary description for ImageFormatConverter.
46 public class ImageFormatConverter : TypeConverter
48 public ImageFormatConverter ()
52 public override bool CanConvertFrom (ITypeDescriptorContext context, Type srcType)
54 if (srcType == typeof (string))
57 return base.CanConvertFrom (context, srcType);
60 public override bool CanConvertTo (ITypeDescriptorContext context, Type destType)
62 if (destType == typeof (string))
65 if (destType == typeof (InstanceDescriptor))
68 return base.CanConvertTo (context, destType);
71 public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object val)
73 string strFormat = val as string;
74 if (strFormat == null)
75 return base.ConvertFrom (context, culture, val);
77 if (strFormat.Equals (ImageFormat.Bmp.ToString ()))
78 return ImageFormat.Bmp;
79 else if (strFormat.Equals (ImageFormat.Emf.ToString ()))
80 return ImageFormat.Emf;
81 else if (strFormat.Equals (ImageFormat.Exif.ToString ()))
82 return ImageFormat.Exif;
83 else if (strFormat.Equals (ImageFormat.Gif.ToString ()))
84 return ImageFormat.Gif;
85 else if (strFormat.Equals (ImageFormat.Icon.ToString ()))
86 return ImageFormat.Icon;
87 else if (strFormat.Equals (ImageFormat.Jpeg.ToString ()))
88 return ImageFormat.Jpeg;
89 else if (strFormat.Equals (ImageFormat.MemoryBmp.ToString ()))
90 return ImageFormat.MemoryBmp;
91 else if (strFormat.Equals (ImageFormat.Png.ToString ()))
92 return ImageFormat.Png;
93 else if (strFormat.Equals (ImageFormat.Tiff.ToString ()))
94 return ImageFormat.Tiff;
95 else if (strFormat.Equals (ImageFormat.Wmf.ToString ()))
96 return ImageFormat.Wmf;
98 return base.ConvertFrom (context, culture, val);
101 public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object val, Type destType )
103 if ((val is ImageFormat) && (destType == typeof (string)))
104 return val.ToString ();
106 if (destType == typeof (InstanceDescriptor) && val is ImageFormat) {
107 ImageFormat c = (ImageFormat) val;
110 if (c.Guid.Equals (ImageFormat.Bmp.Guid))
112 else if (c.Guid.Equals (ImageFormat.Emf.Guid))
114 else if (c.Guid.Equals (ImageFormat.Exif.Guid))
116 else if (c.Guid.Equals (ImageFormat.Gif.Guid))
118 else if (c.Guid.Equals (ImageFormat.Icon.Guid))
120 else if (c.Guid.Equals (ImageFormat.Jpeg.Guid))
122 else if (c.Guid.Equals (ImageFormat.MemoryBmp.Guid))
124 else if (c.Guid.Equals (ImageFormat.Png.Guid))
126 else if (c.Guid.Equals (ImageFormat.Tiff.Guid))
128 else if (c.Guid.Equals (ImageFormat.Wmf.Guid))
132 return new InstanceDescriptor (typeof (ImageFormat).GetProperty (prop), null);
134 ConstructorInfo ctor = typeof(ImageFormat).GetConstructor (new Type[] {typeof(Guid)} );
135 return new InstanceDescriptor (ctor, new object[] {c.Guid});
139 return base.ConvertTo (context, culture, val, destType);
142 [MonoTODO ("Implement")]
143 public override StandardValuesCollection GetStandardValues (ITypeDescriptorContext context )
145 throw new NotImplementedException ();
148 public override bool GetStandardValuesSupported (ITypeDescriptorContext context )