示例#1
0
        private void TestBitmapInfoHeader()
        {
            BitmapInfoHeader w1 = new BitmapInfoHeader();
            FillBMI(w1, 0);

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

            Marshal.FreeCoTaskMem(ip);
        }
示例#2
0
        private void FillBMI(BitmapInfoHeader w1, int iOffset)
        {
            w1.Size = Marshal.SizeOf(typeof(BitmapInfoHeader));
            w1.ClrUsed = 0;
            w1.BitCount = 32;
            w1.Compression = 0;

            w1.ClrImportant = 1 + iOffset;
            w1.Height = 2 + iOffset;
            w1.Planes = (short)(3 + iOffset);
            w1.ImageSize = 4 + iOffset;
            w1.Width = 5 + iOffset;
            w1.XPelsPerMeter = 6 + iOffset;
            w1.YPelsPerMeter = 7 + iOffset;
        }
        void TestGetCurrentImage()
        {
            BitmapInfoHeader bmh = new BitmapInfoHeader();
            int i;
            long l = 0;
            IntPtr ip = IntPtr.Zero;

            bmh.Size = Marshal.SizeOf(typeof(BitmapInfoHeader));

            try
            {
                // Works in BasicPlayer
                int hr = m_vdc.GetCurrentImage(bmh, out ip, out i, out l);
                MFError.ThrowExceptionForHR(hr);
            }
            catch { }
        }
 public void CleanUpManagedData(object ManagedObj)
 {
     m_bmi = null;
 }
        public IntPtr MarshalManagedToNative(object managedObj)
        {
            m_bmi = managedObj as BitmapInfoHeader;

            IntPtr ip = m_bmi.GetPtr();

            return ip;
        }
        public void CopyFrom(BitmapInfoHeader bmi)
        {
            Size = bmi.Size;
            Width = bmi.Width;
            Height = bmi.Height;
            Planes = bmi.Planes;
            BitCount = bmi.BitCount;
            Compression = bmi.Compression;
            ImageSize = bmi.ImageSize;
            YPelsPerMeter = bmi.YPelsPerMeter;
            ClrUsed = bmi.ClrUsed;
            ClrImportant = bmi.ClrImportant;

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

                ext.bmiColors = new int[ext2.bmiColors.Length];
                ext2.bmiColors.CopyTo(ext.bmiColors, 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;
        }
示例#8
0
        private void menuItem8_Click(object sender, EventArgs e)
        {
            MediaFoundation.Misc.BitmapInfoHeader pBih = new MediaFoundation.Misc.BitmapInfoHeader();
            IntPtr pDib = IntPtr.Zero;
            int pcbDib = 0;
            long pTimeStamp = 0;

            try
            {
                pBih.Size = Marshal.SizeOf(pBih);

                int hr = evrDisplay.GetCurrentImage(pBih, out pDib, out pcbDib, out pTimeStamp);
                DsError.ThrowExceptionForHR(hr);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK);
            }
            finally
            {
                if (pDib != IntPtr.Zero)
                    Marshal.FreeCoTaskMem(pDib);
            }
        }