ImageCodecInfo.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. try {
  74. status = GDIPlus.GdipGetImageDecoders (decoderNums, arraySize, decoders);
  75. GDIPlus.CheckStatus (status);
  76. decoder_size = Marshal.SizeOf (gdipdecoder);
  77. decoder_ptr = decoders;
  78. for (int i = 0; i < decoderNums; i++, decoder_ptr = new IntPtr (decoder_ptr.ToInt64 () + decoder_size)) {
  79. gdipdecoder = (GdipImageCodecInfo) Marshal.PtrToStructure (decoder_ptr, typeof (GdipImageCodecInfo));
  80. result[i] = new ImageCodecInfo ();
  81. GdipImageCodecInfo.MarshalTo (gdipdecoder, result[i]);
  82. }
  83. }
  84. finally {
  85. Marshal.FreeHGlobal (decoders);
  86. }
  87. return result;
  88. }
  89. public static ImageCodecInfo[] GetImageEncoders()
  90. {
  91. int encoderNums, arraySize, encoder_size;
  92. IntPtr encoders, encoder_ptr;
  93. ImageCodecInfo[] result;
  94. GdipImageCodecInfo gdipencoder = new GdipImageCodecInfo();
  95. Status status;
  96. status = GDIPlus.GdipGetImageEncodersSize (out encoderNums, out arraySize);
  97. GDIPlus.CheckStatus (status);
  98. result = new ImageCodecInfo [encoderNums];
  99. if (encoderNums == 0)
  100. return result;
  101. /* Get encoders list*/
  102. encoders = Marshal.AllocHGlobal (arraySize);
  103. try {
  104. status = GDIPlus.GdipGetImageEncoders (encoderNums, arraySize, encoders);
  105. GDIPlus.CheckStatus (status);
  106. encoder_size = Marshal.SizeOf (gdipencoder);
  107. encoder_ptr = encoders;
  108. for (int i = 0; i < encoderNums; i++, encoder_ptr = new IntPtr (encoder_ptr.ToInt64 () + encoder_size)) {
  109. gdipencoder = (GdipImageCodecInfo) Marshal.PtrToStructure (encoder_ptr, typeof (GdipImageCodecInfo));
  110. result[i] = new ImageCodecInfo ();
  111. GdipImageCodecInfo.MarshalTo (gdipencoder, result[i]);
  112. }
  113. }
  114. finally {
  115. Marshal.FreeHGlobal (encoders);
  116. }
  117. return result;
  118. }
  119. // properties
  120. public Guid Clsid
  121. {
  122. get { return clsid; }
  123. set { clsid = value; }
  124. }
  125. public string CodecName
  126. {
  127. get { return codecName; }
  128. set { codecName = value; }
  129. }
  130. public string DllName
  131. {
  132. get { return dllName; }
  133. set { dllName = value; }
  134. }
  135. public string FilenameExtension
  136. {
  137. get { return filenameExtension; }
  138. set { filenameExtension = value; }
  139. }
  140. public ImageCodecFlags Flags
  141. {
  142. get { return flags; }
  143. set { flags = value; }
  144. }
  145. public string FormatDescription
  146. {
  147. get { return formatDescription; }
  148. set { formatDescription = value; }
  149. }
  150. public Guid FormatID
  151. {
  152. get { return formatID; }
  153. set { formatID = value; }
  154. }
  155. public string MimeType
  156. {
  157. get { return mimeType; }
  158. set { mimeType = value; }
  159. }
  160. [CLSCompliant(false)]
  161. public byte[][] SignatureMasks
  162. {
  163. get { return signatureMasks; }
  164. set { signatureMasks = value; }
  165. }
  166. [MonoTODO]
  167. [CLSCompliant(false)]
  168. public byte[][] SignaturePatterns
  169. {
  170. get { return signaturePatterns; }
  171. set { signaturePatterns = value; }
  172. }
  173. public int Version
  174. {
  175. get { return version; }
  176. set { version = value; }
  177. }
  178. }
  179. }