ImageCodecInfo.cs 5.5 KB

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