ImageCodecInfo.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. //
  2. // System.Drawing.Imaging.ImageCodecInfo.cs
  3. //
  4. // Authors:
  5. // Everaldo Canuto ([email protected])
  6. // Andreas Nahr ([email protected])
  7. // Dennis Hayes ([email protected])
  8. // Andreas Nahr ([email protected])
  9. // Dennis Hayes ([email protected])
  10. // Jordi Mas i Hernandez ([email protected])
  11. //
  12. // (C) 2002 Ximian, Inc. http://www.ximian.com
  13. // Copyright (C) 2004,2006 Novell, Inc (http://www.novell.com)
  14. //
  15. // Permission is hereby granted, free of charge, to any person obtaining
  16. // a copy of this software and associated documentation files (the
  17. // "Software"), to deal in the Software without restriction, including
  18. // without limitation the rights to use, copy, modify, merge, publish,
  19. // distribute, sublicense, and/or sell copies of the Software, and to
  20. // permit persons to whom the Software is furnished to do so, subject to
  21. // the following conditions:
  22. //
  23. // The above copyright notice and this permission notice shall be
  24. // included in all copies or substantial portions of the Software.
  25. //
  26. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  30. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  31. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  32. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  33. //
  34. using System.Runtime.InteropServices;
  35. using System.Collections;
  36. using System.IO;
  37. namespace System.Drawing.Imaging {
  38. #if ONLY_1_1
  39. [ComVisible (false)]
  40. #endif
  41. public sealed class ImageCodecInfo {
  42. private Guid clsid;
  43. private string codecName;
  44. private string dllName;
  45. private string filenameExtension;
  46. private ImageCodecFlags flags;
  47. private string formatDescription;
  48. private Guid formatID;
  49. private string mimeType;
  50. private byte[][] signatureMasks;
  51. private byte[][] signaturePatterns;
  52. private int version;
  53. internal ImageCodecInfo()
  54. {
  55. }
  56. // methods
  57. public static ImageCodecInfo[] GetImageDecoders()
  58. {
  59. int decoderNums, arraySize, decoder_size;
  60. IntPtr decoders, decoder_ptr;
  61. ImageCodecInfo[] result;
  62. GdipImageCodecInfo gdipdecoder = new GdipImageCodecInfo();
  63. Status status;
  64. status = GDIPlus.GdipGetImageDecodersSize (out decoderNums, out arraySize);
  65. GDIPlus.CheckStatus (status);
  66. result = new ImageCodecInfo [decoderNums];
  67. if (decoderNums == 0)
  68. return result;
  69. /* Get decoders list*/
  70. decoders = Marshal.AllocHGlobal (arraySize);
  71. try {
  72. status = GDIPlus.GdipGetImageDecoders (decoderNums, arraySize, decoders);
  73. GDIPlus.CheckStatus (status);
  74. decoder_size = Marshal.SizeOf (gdipdecoder);
  75. decoder_ptr = decoders;
  76. for (int i = 0; i < decoderNums; i++, decoder_ptr = new IntPtr (decoder_ptr.ToInt64 () + decoder_size)) {
  77. gdipdecoder = (GdipImageCodecInfo) Marshal.PtrToStructure (decoder_ptr, typeof (GdipImageCodecInfo));
  78. result[i] = new ImageCodecInfo ();
  79. GdipImageCodecInfo.MarshalTo (gdipdecoder, result[i]);
  80. }
  81. }
  82. finally {
  83. Marshal.FreeHGlobal (decoders);
  84. }
  85. return result;
  86. }
  87. public static ImageCodecInfo[] GetImageEncoders()
  88. {
  89. int encoderNums, arraySize, encoder_size;
  90. IntPtr encoders, encoder_ptr;
  91. ImageCodecInfo[] result;
  92. GdipImageCodecInfo gdipencoder = new GdipImageCodecInfo();
  93. Status status;
  94. status = GDIPlus.GdipGetImageEncodersSize (out encoderNums, out arraySize);
  95. GDIPlus.CheckStatus (status);
  96. result = new ImageCodecInfo [encoderNums];
  97. if (encoderNums == 0)
  98. return result;
  99. /* Get encoders list*/
  100. encoders = Marshal.AllocHGlobal (arraySize);
  101. try {
  102. status = GDIPlus.GdipGetImageEncoders (encoderNums, arraySize, encoders);
  103. GDIPlus.CheckStatus (status);
  104. encoder_size = Marshal.SizeOf (gdipencoder);
  105. encoder_ptr = encoders;
  106. for (int i = 0; i < encoderNums; i++, encoder_ptr = new IntPtr (encoder_ptr.ToInt64 () + encoder_size)) {
  107. gdipencoder = (GdipImageCodecInfo) Marshal.PtrToStructure (encoder_ptr, typeof (GdipImageCodecInfo));
  108. result[i] = new ImageCodecInfo ();
  109. GdipImageCodecInfo.MarshalTo (gdipencoder, result[i]);
  110. }
  111. }
  112. finally {
  113. Marshal.FreeHGlobal (encoders);
  114. }
  115. return result;
  116. }
  117. // properties
  118. public Guid Clsid
  119. {
  120. get { return clsid; }
  121. set { clsid = value; }
  122. }
  123. public string CodecName
  124. {
  125. get { return codecName; }
  126. set { codecName = value; }
  127. }
  128. public string DllName
  129. {
  130. get { return dllName; }
  131. set { dllName = value; }
  132. }
  133. public string FilenameExtension
  134. {
  135. get { return filenameExtension; }
  136. set { filenameExtension = value; }
  137. }
  138. public ImageCodecFlags Flags
  139. {
  140. get { return flags; }
  141. set { flags = value; }
  142. }
  143. public string FormatDescription
  144. {
  145. get { return formatDescription; }
  146. set { formatDescription = value; }
  147. }
  148. public Guid FormatID
  149. {
  150. get { return formatID; }
  151. set { formatID = value; }
  152. }
  153. public string MimeType
  154. {
  155. get { return mimeType; }
  156. set { mimeType = value; }
  157. }
  158. [CLSCompliant(false)]
  159. public byte[][] SignatureMasks
  160. {
  161. get { return signatureMasks; }
  162. set { signatureMasks = value; }
  163. }
  164. [MonoTODO]
  165. [CLSCompliant(false)]
  166. public byte[][] SignaturePatterns
  167. {
  168. get { return signaturePatterns; }
  169. set { signaturePatterns = value; }
  170. }
  171. public int Version
  172. {
  173. get { return version; }
  174. set { version = value; }
  175. }
  176. }
  177. }