// methods public static ImageCodecInfo[] GetImageDecoders() { int decoderNums, arraySize, decoder_size; IntPtr decoders, decoder_ptr; ImageCodecInfo[] result; GdipImageCodecInfo gdipdecoder = new GdipImageCodecInfo(); Status status; status = GDIPlus.GdipGetImageDecodersSize(out decoderNums, out arraySize); GDIPlus.CheckStatus(status); result = new ImageCodecInfo [decoderNums]; if (decoderNums == 0) { return(result); } /* Get decoders list*/ decoders = Marshal.AllocHGlobal(arraySize); try { status = GDIPlus.GdipGetImageDecoders(decoderNums, arraySize, decoders); GDIPlus.CheckStatus(status); decoder_size = Marshal.SizeOf(gdipdecoder); decoder_ptr = decoders; for (int i = 0; i < decoderNums; i++, decoder_ptr = new IntPtr(decoder_ptr.ToInt64() + decoder_size)) { gdipdecoder = (GdipImageCodecInfo)Marshal.PtrToStructure(decoder_ptr, typeof(GdipImageCodecInfo)); result[i] = new ImageCodecInfo(); GdipImageCodecInfo.MarshalTo(gdipdecoder, result[i]); } } finally { Marshal.FreeHGlobal(decoders); } return(result); }
// methods public static ImageCodecInfo[] GetImageDecoders() { int decoderNums, arraySize, decoder_size; IntPtr decoders, decoder_ptr; ImageCodecInfo[] result; GdipImageCodecInfo gdipdecoder = new GdipImageCodecInfo(); Status status; status = GDIPlus.GdipGetImageDecodersSize (out decoderNums, out arraySize); GDIPlus.CheckStatus (status); result = new ImageCodecInfo [decoderNums]; if (decoderNums == 0) return result; /* Get decoders list*/ decoders = Marshal.AllocHGlobal (arraySize); try { status = GDIPlus.GdipGetImageDecoders (decoderNums, arraySize, decoders); GDIPlus.CheckStatus (status); decoder_size = Marshal.SizeOf (gdipdecoder); decoder_ptr = decoders; for (int i = 0; i < decoderNums; i++, decoder_ptr = new IntPtr (decoder_ptr.ToInt64 () + decoder_size)) { gdipdecoder = (GdipImageCodecInfo) Marshal.PtrToStructure (decoder_ptr, typeof (GdipImageCodecInfo)); result[i] = new ImageCodecInfo (); GdipImageCodecInfo.MarshalTo (gdipdecoder, result[i]); } } finally { Marshal.FreeHGlobal (decoders); } return result; }