Ejemplo n.º 1
0
        public void CopyFrom(BitmapInfoHeader bmi)
        {
            biSize = bmi.biSize;
            biWidth = bmi.biWidth;
            biHeight = bmi.biHeight;
            biPlanes = bmi.biPlanes;
            biBitCount = bmi.biBitCount;
            biCompression = bmi.biCompression;
            biSizeImage = bmi.biSizeImage;
            biSizeImage = bmi.biSizeImage;
            biYPelsPerMeter = bmi.biYPelsPerMeter;
            biClrUsed = bmi.biClrUsed;
            biClrImportant = bmi.biClrImportant;

            if(bmi is BitmapInfoHeaderWithData)
            {
                var ext = this as BitmapInfoHeaderWithData;
                var ext2 = bmi as BitmapInfoHeaderWithData;

                ext.bmiColors = new int[ext2.bmiColors.Length];
                ext2.bmiColors.CopyTo(ext.bmiColors, 0);
            }
        }
Ejemplo n.º 2
0
        public IntPtr MarshalManagedToNative(object managedObj)
        {
            m_bmi = managedObj as BitmapInfoHeader;

            IntPtr ip = m_bmi.GetPtr();

            return ip;
        }
Ejemplo n.º 3
0
        public static BitmapInfoHeader PtrToBMI(IntPtr pNativeData)
        {
            int iEntries;
            int biCompression;
            int biClrUsed;
            int biBitCount;

            biBitCount = Marshal.ReadInt16(pNativeData, 14);
            biCompression = Marshal.ReadInt32(pNativeData, 16);
            biClrUsed = Marshal.ReadInt32(pNativeData, 32);

            if(biCompression == 3) // BI_BITFIELDS
            {
                iEntries = 3;
            }
            else if(biClrUsed > 0)
            {
                iEntries = biClrUsed;
            }
            else if(biBitCount <= 8)
            {
                iEntries = 1 << biBitCount;
            }
            else
            {
                iEntries = 0;
            }

            BitmapInfoHeader bmi;

            if(iEntries == 0)
            {
                // Create a simple BitmapInfoHeader struct
                bmi = new BitmapInfoHeader();
                Marshal.PtrToStructure(pNativeData, bmi);
            }
            else
            {
                var ext = new BitmapInfoHeaderWithData();

                ext.biSize = Marshal.ReadInt32(pNativeData, 0);
                ext.biWidth = Marshal.ReadInt32(pNativeData, 4);
                ext.biHeight = Marshal.ReadInt32(pNativeData, 8);
                ext.biPlanes = Marshal.ReadInt16(pNativeData, 12);
                ext.biBitCount = Marshal.ReadInt16(pNativeData, 14);
                ext.biCompression = Marshal.ReadInt32(pNativeData, 16);
                ext.biSizeImage = Marshal.ReadInt32(pNativeData, 20);
                ext.biXPelsPerMeter = Marshal.ReadInt32(pNativeData, 24);
                ext.biYPelsPerMeter = Marshal.ReadInt32(pNativeData, 28);
                ext.biClrUsed = Marshal.ReadInt32(pNativeData, 32);
                ext.biClrImportant = Marshal.ReadInt32(pNativeData, 36);

                bmi = ext;

                ext.bmiColors = new int[iEntries];
                var ip2 = new IntPtr(pNativeData.ToInt64() + Marshal.SizeOf(typeof(BitmapInfoHeader)));
                Marshal.Copy(ip2, ext.bmiColors, 0, iEntries);
            }

            return bmi;
        }
Ejemplo n.º 4
0
 // It appears this routine is never called
 public void CleanUpManagedData(object ManagedObj)
 {
     m_bmi = null;
 }