Example #1
0
 private static ImageCodecInfo[] ConvertFromMemory(IntPtr memoryStart, int numCodecs)
 {
     ImageCodecInfo[] infoArray = new ImageCodecInfo[numCodecs];
     for (int i = 0; i < numCodecs; i++)
     {
         IntPtr lparam = (IntPtr)(((long)memoryStart) + (Marshal.SizeOf(typeof(ImageCodecInfoPrivate)) * i));
         ImageCodecInfoPrivate data = new ImageCodecInfoPrivate();
         System.Drawing.UnsafeNativeMethods.PtrToStructure(lparam, data);
         infoArray[i]                   = new ImageCodecInfo();
         infoArray[i].Clsid             = data.Clsid;
         infoArray[i].FormatID          = data.FormatID;
         infoArray[i].CodecName         = Marshal.PtrToStringUni(data.CodecName);
         infoArray[i].DllName           = Marshal.PtrToStringUni(data.DllName);
         infoArray[i].FormatDescription = Marshal.PtrToStringUni(data.FormatDescription);
         infoArray[i].FilenameExtension = Marshal.PtrToStringUni(data.FilenameExtension);
         infoArray[i].MimeType          = Marshal.PtrToStringUni(data.MimeType);
         infoArray[i].Flags             = (ImageCodecFlags)data.Flags;
         infoArray[i].Version           = data.Version;
         infoArray[i].SignaturePatterns = new byte[data.SigCount][];
         infoArray[i].SignatureMasks    = new byte[data.SigCount][];
         for (int j = 0; j < data.SigCount; j++)
         {
             infoArray[i].SignaturePatterns[j] = new byte[data.SigSize];
             infoArray[i].SignatureMasks[j]    = new byte[data.SigSize];
             Marshal.Copy((IntPtr)(((long)data.SigMask) + (j * data.SigSize)), infoArray[i].SignatureMasks[j], 0, data.SigSize);
             Marshal.Copy((IntPtr)(((long)data.SigPattern) + (j * data.SigSize)), infoArray[i].SignaturePatterns[j], 0, data.SigSize);
         }
     }
     return(infoArray);
 }
 private static ImageCodecInfo[] ConvertFromMemory(IntPtr memoryStart, int numCodecs)
 {
     ImageCodecInfo[] infoArray = new ImageCodecInfo[numCodecs];
     for (int i = 0; i < numCodecs; i++)
     {
         IntPtr lparam = (IntPtr) (((long) memoryStart) + (Marshal.SizeOf(typeof(ImageCodecInfoPrivate)) * i));
         ImageCodecInfoPrivate data = new ImageCodecInfoPrivate();
         System.Drawing.UnsafeNativeMethods.PtrToStructure(lparam, data);
         infoArray[i] = new ImageCodecInfo();
         infoArray[i].Clsid = data.Clsid;
         infoArray[i].FormatID = data.FormatID;
         infoArray[i].CodecName = Marshal.PtrToStringUni(data.CodecName);
         infoArray[i].DllName = Marshal.PtrToStringUni(data.DllName);
         infoArray[i].FormatDescription = Marshal.PtrToStringUni(data.FormatDescription);
         infoArray[i].FilenameExtension = Marshal.PtrToStringUni(data.FilenameExtension);
         infoArray[i].MimeType = Marshal.PtrToStringUni(data.MimeType);
         infoArray[i].Flags = (ImageCodecFlags) data.Flags;
         infoArray[i].Version = data.Version;
         infoArray[i].SignaturePatterns = new byte[data.SigCount][];
         infoArray[i].SignatureMasks = new byte[data.SigCount][];
         for (int j = 0; j < data.SigCount; j++)
         {
             infoArray[i].SignaturePatterns[j] = new byte[data.SigSize];
             infoArray[i].SignatureMasks[j] = new byte[data.SigSize];
             Marshal.Copy((IntPtr) (((long) data.SigMask) + (j * data.SigSize)), infoArray[i].SignatureMasks[j], 0, data.SigSize);
             Marshal.Copy((IntPtr) (((long) data.SigPattern) + (j * data.SigSize)), infoArray[i].SignaturePatterns[j], 0, data.SigSize);
         }
     }
     return infoArray;
 }
Example #3
0
        private static ImageCodecInfo[] ConvertFromMemory(IntPtr memoryStart, int numCodecs)
        {
            ImageCodecInfo[] codecs = new ImageCodecInfo[numCodecs];

            int index;

            for (index = 0; index < numCodecs; index++)
            {
                IntPtr curcodec = (IntPtr)((long)memoryStart + (int)Marshal.SizeOf(typeof(ImageCodecInfoPrivate)) * index);
                ImageCodecInfoPrivate codecp = new ImageCodecInfoPrivate();
                Marshal.PtrToStructure(curcodec, codecp);

                codecs[index]                   = new ImageCodecInfo();
                codecs[index].Clsid             = codecp.Clsid;
                codecs[index].FormatID          = codecp.FormatID;
                codecs[index].CodecName         = Marshal.PtrToStringUni(codecp.CodecName);
                codecs[index].DllName           = Marshal.PtrToStringUni(codecp.DllName);
                codecs[index].FormatDescription = Marshal.PtrToStringUni(codecp.FormatDescription);
                codecs[index].FilenameExtension = Marshal.PtrToStringUni(codecp.FilenameExtension);
                codecs[index].MimeType          = Marshal.PtrToStringUni(codecp.MimeType);

                codecs[index].Flags   = (ImageCodecFlags)codecp.Flags;
                codecs[index].Version = (int)codecp.Version;

                codecs[index].SignaturePatterns = new byte[codecp.SigCount][];
                codecs[index].SignatureMasks    = new byte[codecp.SigCount][];

                for (int j = 0; j < codecp.SigCount; j++)
                {
                    codecs[index].SignaturePatterns ![j] = new byte[codecp.SigSize];
 internal static void FreeMemory(ImageCodecInfoPrivate imagecodecp)
 {
     Marshal.FreeHGlobal(imagecodecp.CodecName);
     Marshal.FreeHGlobal(imagecodecp.FormatDescription);
     Marshal.FreeHGlobal(imagecodecp.FilenameExtension);
     Marshal.FreeHGlobal(imagecodecp.MimeType);
     Marshal.FreeHGlobal(imagecodecp.SigPattern);
     Marshal.FreeHGlobal(imagecodecp.SigMask);
 }
        internal static ImageCodecInfoPrivate ConvertToMemory(ImageCodecInfo imagecs)
        {
            ImageCodecInfoPrivate imagecsp = new ImageCodecInfoPrivate();

            imagecsp.Clsid    = imagecs.Clsid;
            imagecsp.FormatID = imagecs.FormatID;

            imagecsp.CodecName         = Marshal.StringToHGlobalUni(imagecs.CodecName);
            imagecsp.DllName           = Marshal.StringToHGlobalUni(imagecs.DllName);
            imagecsp.FormatDescription = Marshal.StringToHGlobalUni(imagecs.FormatDescription);
            imagecsp.FilenameExtension = Marshal.StringToHGlobalUni(imagecs.FilenameExtension);
            imagecsp.MimeType          = Marshal.StringToHGlobalUni(imagecs.MimeType);

            imagecsp.Flags    = (int)imagecs.Flags;
            imagecsp.Version  = (int)imagecs.Version;
            imagecsp.SigCount = imagecs.SignaturePatterns.Length;
            imagecsp.SigSize  = imagecs.SignaturePatterns[0].Length;

            imagecsp.SigPattern = Marshal.AllocHGlobal(imagecsp.SigCount * imagecsp.SigSize);
            imagecsp.SigMask    = Marshal.AllocHGlobal(imagecsp.SigCount * imagecsp.SigSize);

            for (int i = 0; i < imagecsp.SigCount; i++)
            {
                Marshal.Copy(imagecs.SignaturePatterns[i],
                             0,
                             (IntPtr)((long)imagecsp.SigPattern + i * imagecsp.SigSize),
                             imagecsp.SigSize);

                Marshal.Copy(imagecs.SignatureMasks[i],
                             0,
                             (IntPtr)((long)imagecsp.SigMask + i * imagecsp.SigSize),
                             imagecsp.SigSize);
            }

            return(imagecsp);
        }
        /* FxCop rule 'AvoidBuildingNonCallableCode' - Left here in case it is needed in the future.
         internal static ImageCodecInfoPrivate ConvertToMemory(ImageCodecInfo imagecs)
         {
             ImageCodecInfoPrivate imagecsp = new ImageCodecInfoPrivate();
             
             imagecsp.Clsid = imagecs.Clsid;
             imagecsp.FormatID = imagecs.FormatID;
             
             imagecsp.CodecName = Marshal.StringToHGlobalUni(imagecs.CodecName);
             imagecsp.DllName = Marshal.StringToHGlobalUni(imagecs.DllName);
             imagecsp.FormatDescription = Marshal.StringToHGlobalUni(imagecs.FormatDescription);
             imagecsp.FilenameExtension = Marshal.StringToHGlobalUni(imagecs.FilenameExtension);
             imagecsp.MimeType = Marshal.StringToHGlobalUni(imagecs.MimeType);
             
             imagecsp.Flags = (int)imagecs.Flags;
             imagecsp.Version = (int)imagecs.Version;
             imagecsp.SigCount = imagecs.SignaturePatterns.Length;
             imagecsp.SigSize = imagecs.SignaturePatterns[0].Length;
             
             imagecsp.SigPattern = Marshal.AllocHGlobal(imagecsp.SigCount*imagecsp.SigSize);
             imagecsp.SigMask = Marshal.AllocHGlobal(imagecsp.SigCount*imagecsp.SigSize);
             
             for (int i=0; i<imagecsp.SigCount; i++)
             {
                 Marshal.Copy(imagecs.SignaturePatterns[i], 
                              0, 
                              (IntPtr)((long)imagecsp.SigPattern + i*imagecsp.SigSize), 
                              imagecsp.SigSize);
                                  
                 Marshal.Copy(imagecs.SignatureMasks[i], 
                              0, 
                              (IntPtr)((long)imagecsp.SigMask + i*imagecsp.SigSize), 
                              imagecsp.SigSize);
             }
                          
             return imagecsp;
         }

         internal static void FreeMemory(ImageCodecInfoPrivate imagecodecp)
         {
             Marshal.FreeHGlobal(imagecodecp.CodecName);
             Marshal.FreeHGlobal(imagecodecp.FormatDescription);
             Marshal.FreeHGlobal(imagecodecp.FilenameExtension);
             Marshal.FreeHGlobal(imagecodecp.MimeType);
             Marshal.FreeHGlobal(imagecodecp.SigPattern);
             Marshal.FreeHGlobal(imagecodecp.SigMask);
         }
         */
               
         private static ImageCodecInfo[] ConvertFromMemory(IntPtr memoryStart, int numCodecs)
         {
             ImageCodecInfo[] codecs = new ImageCodecInfo[numCodecs];

             int index;

             for (index=0; index<numCodecs; index++)
             {
                 IntPtr curcodec = (IntPtr)((long)memoryStart + (int)Marshal.SizeOf(typeof(ImageCodecInfoPrivate))*index);
                 ImageCodecInfoPrivate codecp = new ImageCodecInfoPrivate();
                 UnsafeNativeMethods.PtrToStructure(curcodec, codecp);
                 
                 codecs[index] = new ImageCodecInfo();
                 codecs[index].Clsid = codecp.Clsid;
                 codecs[index].FormatID = codecp.FormatID;
                 codecs[index].CodecName = Marshal.PtrToStringUni(codecp.CodecName);
                 codecs[index].DllName = Marshal.PtrToStringUni(codecp.DllName);
                 codecs[index].FormatDescription = Marshal.PtrToStringUni(codecp.FormatDescription);
                 codecs[index].FilenameExtension = Marshal.PtrToStringUni(codecp.FilenameExtension);
                 codecs[index].MimeType = Marshal.PtrToStringUni(codecp.MimeType);
                 
                 codecs[index].Flags = (ImageCodecFlags)codecp.Flags;
                 codecs[index].Version = (int)codecp.Version;
                                  
                 codecs[index].SignaturePatterns = new byte[codecp.SigCount][];
                 codecs[index].SignatureMasks = new byte[codecp.SigCount][];
                 
                 for (int j=0; j<codecp.SigCount; j++)
                 {
                     codecs[index].SignaturePatterns[j] = new byte[codecp.SigSize];
                     codecs[index].SignatureMasks[j] = new byte[codecp.SigSize];

                     Marshal.Copy((IntPtr)((long)codecp.SigMask + j*codecp.SigSize), codecs[index].SignatureMasks[j], 0, codecp.SigSize);
                     Marshal.Copy((IntPtr)((long)codecp.SigPattern + j*codecp.SigSize), codecs[index].SignaturePatterns[j], 0, codecp.SigSize);
                 }
             }

             return codecs;
         }