**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Drawing / System.Drawing / ImageFormatConverter.cs
blob192321efa1254a71056c97e726fa29ac5ad0aec0
1 //
2 // System.Drawing.ImageFormatConverter.cs
3 //
4 // Author:
5 // Dennis Hayes (dennish@Raytek.com)
6 // Sanjay Gupta (gsanjay@novell.com)
7 //
8 // (C) 2002 Ximian, Inc
9 //
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:
21 //
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 //
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.
34 using System;
35 using System.ComponentModel;
36 using System.Globalization;
37 using System.Drawing.Imaging;
39 namespace System.Drawing
41 /// <summary>
42 /// Summary description for ImageFormatConverter.
43 /// </summary>
44 public class ImageFormatConverter : TypeConverter
46 public ImageFormatConverter ()
50 public override bool CanConvertFrom (ITypeDescriptorContext context, Type srcType)
52 if (srcType == typeof (string))
53 return true;
54 else
55 return false;
58 public override bool CanConvertTo (ITypeDescriptorContext context, Type destType)
60 if (destType == typeof (string))
61 return true;
62 else
63 return false;
66 public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object val)
68 string strFormat = val as string;
69 if (strFormat == null)
70 return base.ConvertFrom (context, culture, val);
72 if (strFormat.Equals (ImageFormat.Bmp.ToString ()))
73 return ImageFormat.Bmp;
74 else if (strFormat.Equals (ImageFormat.Emf.ToString ()))
75 return ImageFormat.Emf;
76 else if (strFormat.Equals (ImageFormat.Exif.ToString ()))
77 return ImageFormat.Exif;
78 else if (strFormat.Equals (ImageFormat.Gif.ToString ()))
79 return ImageFormat.Gif;
80 else if (strFormat.Equals (ImageFormat.Icon.ToString ()))
81 return ImageFormat.Icon;
82 else if (strFormat.Equals (ImageFormat.Jpeg.ToString ()))
83 return ImageFormat.Jpeg;
84 else if (strFormat.Equals (ImageFormat.MemoryBmp.ToString ()))
85 return ImageFormat.MemoryBmp;
86 else if (strFormat.Equals (ImageFormat.Png.ToString ()))
87 return ImageFormat.Png;
88 else if (strFormat.Equals (ImageFormat.Tiff.ToString ()))
89 return ImageFormat.Tiff;
90 else if (strFormat.Equals (ImageFormat.Wmf.ToString ()))
91 return ImageFormat.Wmf;
92 else
93 throw new NotSupportedException ("ImageFormatConverter cannot convert from " + val.GetType ());
96 public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object val, Type destType )
98 if ((val is ImageFormat) && (destType == typeof (string)))
99 return val.ToString ();
101 throw new NotSupportedException ("ImageFormatConverter can not convert from " + val.GetType ());
104 [MonoTODO ("Implement")]
105 public override StandardValuesCollection GetStandardValues (ITypeDescriptorContext context )
107 throw new NotImplementedException ();
110 public override bool GetStandardValuesSupported (ITypeDescriptorContext context )
112 return false;