Esempio n. 1
0
        protected override IntPtr CreatePixmapHandle(int width, int height, BitCount bitsperpixel)
        {
            //Orientation = orient;
            PixmapOrientation orient = PixmapOrientation.BottomToTop;

            // Create a bitmap compatible with the screen
            fBitmapInfo = new BITMAPINFO();
            fBitmapInfo.Init();


            m_BytesPerRow = GDIPixmap.GetAlignedRowStride(Width, bitsperpixel, Alignment);
            fBitmapInfo.bmiHeader.biWidth = Width;

            if (PixmapOrientation.TopToBottom == orient)
                fBitmapInfo.bmiHeader.biHeight = -Height;   // Indicates a top-to-bottom orientation
            else
                fBitmapInfo.bmiHeader.biHeight = Height;

            fBitmapInfo.bmiHeader.biPlanes = 1;
            fBitmapInfo.bmiHeader.biBitCount = (ushort)bitsperpixel;
            fBitmapInfo.bmiHeader.biSizeImage = (uint)(m_BytesPerRow * Height);
            fBitmapInfo.bmiHeader.biClrImportant = 0;
            fBitmapInfo.bmiHeader.biClrUsed = 0;
            fBitmapInfo.bmiHeader.biCompression = GDI32.BI_RGB;
            //fBitmapInfo.bmiColors = IntPtr.Zero;

            m_pixelPointer = IntPtr.Zero;

            IntPtr bitmapHandle = GDI32.CreateDIBSection(GDIContext.CreateForDefaultDisplay(),
                ref fBitmapInfo, GDI32.DIB_RGB_COLORS, ref m_pixelPointer, IntPtr.Zero, 0);

            return bitmapHandle;
        }
Esempio n. 2
0
        public static BITMAPINFO ToBitmapInfo(this PixelRectangleInfo pixmap)
        {
            BITMAPINFO bmi = new BITMAPINFO();
            bmi.Init();

            bmi.bmiHeader.biBitCount = (ushort)pixmap.BitsPerPixel;
            bmi.bmiHeader.biWidth = pixmap.Width;

            if (pixmap.Orientation == PixmapOrientation.TopToBottom)
                bmi.bmiHeader.biHeight = -pixmap.Height;
            else
                bmi.bmiHeader.biHeight = pixmap.Height;

            bmi.bmiHeader.biSizeImage = (uint)pixmap.GetImageSize();
            bmi.bmiHeader.biPlanes = 1;
            bmi.bmiHeader.biClrImportant = 0;
            bmi.bmiHeader.biClrUsed = 0;
            bmi.bmiHeader.biCompression = 0;

            return bmi;
        }
Esempio n. 3
0
        public Form1()
            :base("GDI Video", 10, 10, 1024, 480)
        {
            fScreenContext = GDIContext.CreateForDefaultDisplay();

            fCamera = new VfwCameraDevice(0, 320, 240, 15, User32.WS_CHILD | User32.WS_VISIBLE, this.Handle);
            //fCamera = new VfwCameraDevice(320, 240);
            fCamera.FrameDelegate = FrameReceived;
            fBitmapInfo = fCamera.GetBitmapInfo();

            fDecompressor = VfwDeCompressor.Create(Vfw.ICTYPE_VIDEO);

            // Allocate a pixel buffer to receive decompressed bits
            //fPixelBuffer = new PixelBuffer24(fCamera.Width, fCamera.Height);

            //fCamera.StartStreaming();
            fCamera.PreviewRate = 33;
            //fCamera.ShowPreviewWindow();

            fCaptureDispatcher = new TimedDispatcher(1.0 / 15, CaptureFrame, null);
            fCaptureDispatcher.Start();
        }
Esempio n. 4
0
        void ConfigureVideoFormat()
        {
            fBitmapInfo = new BITMAPINFO();
            fBitmapInfo.Init();

            fBitmapInfo.bmiHeader = new BITMAPINFOHEADER();
            fBitmapInfo.bmiHeader.Init();

            // Get the current format information
            int formatSize = capGetVideoFormatSize();
            capGetVideoFormat(ref fBitmapInfo);

            PrintCompressionType(fBitmapInfo.bmiHeader.biCompression);

            // Fill in the things we want to change
            fBitmapInfo.bmiHeader.biWidth = Width;
            fBitmapInfo.bmiHeader.biHeight = Height;
            fBitmapInfo.bmiHeader.biPlanes = 1;
            fBitmapInfo.bmiHeader.biBitCount = 24; // 24 bits per frame - RGB
            fBitmapInfo.bmiHeader.biCompression = GDI32.BI_RGB;

            // Try to set the video format
            bool setSuccess = capSetVideoFormat(ref fBitmapInfo);

            // Get the settings again, and set the width
            // and height based on what was actually set
            capGetVideoFormat(ref fBitmapInfo);
            Width = fBitmapInfo.bmiHeader.biWidth;
            Height = fBitmapInfo.bmiHeader.biHeight;
        }
        public virtual int PixelBlt(Rectangle srcRect, Rectangle dstRect, IntPtr pixelPtr, BitCount bitsPerPixel)
        {

            BITMAPINFO bmInfo = new BITMAPINFO();
            bmInfo.Init();
            bmInfo.bmiHeader.biWidth = srcRect.Width;
            bmInfo.bmiHeader.biHeight = srcRect.Height;
            bmInfo.bmiHeader.biPlanes = 1;
            bmInfo.bmiHeader.biBitCount = (ushort)bitsPerPixel;
            bmInfo.bmiHeader.biClrImportant = 0;
            bmInfo.bmiHeader.biClrUsed = 0;
            bmInfo.bmiHeader.biCompression = GDI32.BI_RGB;
            //bmInfo.bmiColors = IntPtr.Zero;

            int rowsWritten = GDI32.StretchDIBits(this,
                dstRect.X, dstRect.Y, dstRect.Width, dstRect.Height,
                srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
                pixelPtr,
                ref bmInfo,
                GDI32.DIB_RGB_COLORS,
                (uint)TernaryRasterOps.SRCCOPY);

            return rowsWritten;
        }
Esempio n. 6
0
 public static extern int SendMessageW([In] IntPtr hWnd, int Msg, uint wParam, ref BITMAPINFO caps);
Esempio n. 7
0
 protected bool capSetVideoFormat(ref BITMAPINFO s)
 {
     int wSize = Marshal.SizeOf(s);
     bool success = 1 == SendMessageW(fWindowHandle, Vfw.WM_CAP_SET_VIDEOFORMAT, (uint)wSize, ref s);
     return success;
 }
Esempio n. 8
0
        /// <summary>
        /// Retrieves a copy of the video format information.
        /// </summary>
        /// <param name="s"></param>
        /// <returns>Returns 0 if not connected to driver.</returns>
        protected int capGetVideoFormat(ref BITMAPINFO s)
        {
            int wSize = Marshal.SizeOf(s);
            int  bytesCopied = SendMessageW(fWindowHandle, Vfw.WM_CAP_GET_VIDEOFORMAT, (uint)wSize, ref s);

            return bytesCopied;
        }
Esempio n. 9
0
        // Generalized bit block transfer
        // Can transfer from any device context to this one.
        public virtual void PixBlt(IPixelArray pixmap, int x, int y)
        {
            if (null == pixmap)
                return;

            BITMAPINFO bmi = new BITMAPINFO();
            bmi.Init();
            
            bmi.bmiHeader.biBitCount = (ushort)pixmap.BitsPerPixel;
            bmi.bmiHeader.biWidth = pixmap.Width;

            if (pixmap.Orientation == PixmapOrientation.TopToBottom)
                bmi.bmiHeader.biHeight = -pixmap.Height;
            else
                bmi.bmiHeader.biHeight = pixmap.Height;

            bmi.bmiHeader.biSizeImage = (uint)(pixmap.BytesPerRow * pixmap.Height);
            bmi.bmiHeader.biPlanes = 1;
            bmi.bmiHeader.biClrImportant = 0;
            bmi.bmiHeader.biClrUsed = 0;
            bmi.bmiHeader.biCompression = 0;

            int result = GDI32.StretchDIBits(DeviceContext, x, y, pixmap.Width, pixmap.Height, 0, 0, pixmap.Width, pixmap.Height, pixmap.Pixels,
                ref bmi, GDI32.DIB_RGB_COLORS, (uint)TernaryRasterOps.SRCCOPY);

            //Console.WriteLine("Result: {0}", result);
        }