ImageCodecInfo.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. using System;
  15. using System.Runtime.InteropServices;
  16. using System.Collections;
  17. using System.IO;
  18. namespace System.Drawing.Imaging {
  19. [ComVisible (false)]
  20. public sealed class ImageCodecInfo
  21. {
  22. private Guid clsid;
  23. private string codecName;
  24. private string dllName;
  25. private string filenameExtension;
  26. private ImageCodecFlags flags;
  27. private string formatDescription;
  28. private Guid formatID;
  29. private string mimeType;
  30. private byte[][] signatureMasks;
  31. private byte[][] signaturePatterns;
  32. private int version;
  33. internal ImageCodecInfo()
  34. {
  35. }
  36. // methods
  37. public static ImageCodecInfo[] GetImageDecoders()
  38. {
  39. int decoderNums, arraySize, decoder_ptr, decoder_size;
  40. IntPtr decoders;
  41. ImageCodecInfo codecinfo = new ImageCodecInfo();
  42. ImageCodecInfo[] result;
  43. GdipImageCodecInfo gdipdecoder = new GdipImageCodecInfo();
  44. Status status;
  45. status = GDIPlus.GdipGetImageDecodersSize (out decoderNums, out arraySize);
  46. GDIPlus.CheckStatus (status);
  47. result = new ImageCodecInfo [decoderNums];
  48. if (decoderNums == 0)
  49. return result;
  50. /* Get decoders list*/
  51. decoders = Marshal.AllocHGlobal (arraySize);
  52. status = GDIPlus.GdipGetImageDecoders (decoderNums, arraySize, decoders);
  53. GDIPlus.CheckStatus (status);
  54. decoder_size = Marshal.SizeOf (gdipdecoder);
  55. decoder_ptr = decoders.ToInt32();
  56. for (int i = 0; i < decoderNums; i++, decoder_ptr += decoder_size)
  57. {
  58. gdipdecoder = (GdipImageCodecInfo) Marshal.PtrToStructure ((IntPtr)decoder_ptr, typeof (GdipImageCodecInfo));
  59. result[i] = new ImageCodecInfo ();
  60. GdipImageCodecInfo.MarshalTo (gdipdecoder, result[i]);
  61. }
  62. Marshal.FreeHGlobal (decoders);
  63. return result;
  64. }
  65. public static ImageCodecInfo[] GetImageEncoders()
  66. {
  67. int encoderNums, arraySize, encoder_ptr, encoder_size;
  68. IntPtr encoders;
  69. ImageCodecInfo codecinfo = new ImageCodecInfo();
  70. ImageCodecInfo[] result;
  71. GdipImageCodecInfo gdipencoder = new GdipImageCodecInfo();
  72. Status status;
  73. status = GDIPlus.GdipGetImageEncodersSize (out encoderNums, out arraySize);
  74. GDIPlus.CheckStatus (status);
  75. result = new ImageCodecInfo [encoderNums];
  76. if (encoderNums == 0)
  77. return result;
  78. /* Get encoders list*/
  79. encoders = Marshal.AllocHGlobal (arraySize);
  80. status = GDIPlus.GdipGetImageEncoders (encoderNums, arraySize, encoders);
  81. GDIPlus.CheckStatus (status);
  82. encoder_size = Marshal.SizeOf (gdipencoder);
  83. encoder_ptr = encoders.ToInt32();
  84. for (int i = 0; i < encoderNums; i++, encoder_ptr += encoder_size)
  85. {
  86. gdipencoder = (GdipImageCodecInfo) Marshal.PtrToStructure ((IntPtr)encoder_ptr, typeof (GdipImageCodecInfo));
  87. result[i] = new ImageCodecInfo ();
  88. GdipImageCodecInfo.MarshalTo (gdipencoder, result[i]);
  89. }
  90. Marshal.FreeHGlobal (encoders);
  91. return result;
  92. }
  93. // properties
  94. public Guid Clsid
  95. {
  96. get { return clsid; }
  97. set { clsid = value; }
  98. }
  99. public string CodecName
  100. {
  101. get { return codecName; }
  102. set { codecName = value; }
  103. }
  104. public string DllName
  105. {
  106. get { return dllName; }
  107. set { dllName = value; }
  108. }
  109. public string FilenameExtension
  110. {
  111. get { return filenameExtension; }
  112. set { filenameExtension = value; }
  113. }
  114. public ImageCodecFlags Flags
  115. {
  116. get { return flags; }
  117. set { flags = value; }
  118. }
  119. public string FormatDescription
  120. {
  121. get { return formatDescription; }
  122. set { formatDescription = value; }
  123. }
  124. public Guid FormatID
  125. {
  126. get { return formatID; }
  127. set { formatID = value; }
  128. }
  129. public string MimeType
  130. {
  131. get { return mimeType; }
  132. set { mimeType = value; }
  133. }
  134. [CLSCompliant(false)]
  135. public byte[][] SignatureMasks
  136. {
  137. get { return signatureMasks; }
  138. set { signatureMasks = value; }
  139. }
  140. [MonoTODO]
  141. [CLSCompliant(false)]
  142. public byte[][] SignaturePatterns
  143. {
  144. get { return signaturePatterns; }
  145. set { signaturePatterns = value; }
  146. }
  147. public int Version
  148. {
  149. get { return version; }
  150. set { version = value; }
  151. }
  152. }
  153. }