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
;
39 namespace System
.Drawing
42 /// Summary description for ImageFormatConverter.
44 public class ImageFormatConverter
: TypeConverter
46 public ImageFormatConverter ()
50 public override bool CanConvertFrom (ITypeDescriptorContext context
, Type srcType
)
52 if (srcType
== typeof (string))
58 public override bool CanConvertTo (ITypeDescriptorContext context
, Type destType
)
60 if (destType
== typeof (string))
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
;
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
)