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