Ejemplo n.º 1
0
        private void TestBitmapInfoHeaderWithData()
        {
            BitmapInfoHeaderWithData w1 = new BitmapInfoHeaderWithData();
            FillBMI(w1, 0);
            w1.bmiColors = new int[] { 1, 2, 3 };
            w1.Compression = 3;

            IntPtr ip = w1.GetPtr();
            BitmapInfoHeaderWithData w2 = BitmapInfoHeader.PtrToBMI(ip) as BitmapInfoHeaderWithData;

            Marshal.FreeCoTaskMem(ip);
        }
Ejemplo n.º 2
0
        private void TestBitmapInfoHeaderWithData3()
        {
            BitmapInfoHeaderWithData w1 = new BitmapInfoHeaderWithData();
            FillBMI(w1, 0);
            w1.bmiColors = new int[256];
            w1.Compression = 0;
            w1.ClrUsed = 0;
            w1.BitCount = 8;

            for (int x = 0; x < 256; x++)
            {
                w1.bmiColors[x] = x + 7;
            }

            IntPtr ip = w1.GetPtr();
            BitmapInfoHeaderWithData w2 = BitmapInfoHeader.PtrToBMI(ip) as BitmapInfoHeaderWithData;

            Marshal.FreeCoTaskMem(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
            {
                BitmapInfoHeaderWithData ext = new BitmapInfoHeaderWithData();

                ext.Size = Marshal.ReadInt32(pNativeData, 0);
                ext.Width = Marshal.ReadInt32(pNativeData, 4);
                ext.Height = Marshal.ReadInt32(pNativeData, 8);
                ext.Planes = Marshal.ReadInt16(pNativeData, 12);
                ext.BitCount = Marshal.ReadInt16(pNativeData, 14);
                ext.Compression = Marshal.ReadInt32(pNativeData, 16);
                ext.ImageSize = Marshal.ReadInt32(pNativeData, 20);
                ext.XPelsPerMeter = Marshal.ReadInt32(pNativeData, 24);
                ext.YPelsPerMeter = Marshal.ReadInt32(pNativeData, 28);
                ext.ClrUsed = Marshal.ReadInt32(pNativeData, 32);
                ext.ClrImportant = Marshal.ReadInt32(pNativeData, 36);

                bmi = ext as BitmapInfoHeader;

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

            return bmi;
        }