void TestGetImage()
        {
            int    hr;
            int    iSize = 0;
            IntPtr ip;

            hr = m_ibv.GetCurrentImage(ref iSize, IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);

            ip = Marshal.AllocCoTaskMem(iSize);

            hr = m_ibv.GetCurrentImage(ref iSize, ip);
            DsError.ThrowExceptionForHR(hr);

            Marshal.FreeCoTaskMem(ip);
        }
Exemple #2
0
        public override bool GetCurrentImage(out BITMAPINFOHEADER header, out IntPtr dibFull, out IntPtr dibDataOnly)
        {
            int bufferSize = 0;
            int hr         = BasicVideo2.GetCurrentImage(ref bufferSize, IntPtr.Zero); // get the required buffer size first

            if (DsHlp.SUCCEEDED(hr))
            {
                dibFull = Marshal.AllocCoTaskMem(bufferSize);
                hr      = BasicVideo2.GetCurrentImage(ref bufferSize, dibFull); // actually get the image
                if (DsHlp.SUCCEEDED(hr))
                {
                    header      = (BITMAPINFOHEADER)Marshal.PtrToStructure(dibFull, typeof(BITMAPINFOHEADER));
                    dibDataOnly = new IntPtr(dibFull.ToInt64() + Marshal.SizeOf(typeof(BITMAPINFOHEADER)));
                    return(true);
                }
            }

            header      = new BITMAPINFOHEADER();
            dibDataOnly = IntPtr.Zero;
            dibFull     = IntPtr.Zero;
            return(false);
        }