示例#1
0
    // Update the image container for the currently registered formats
    private void UpdateImageContainer()
    {
        CameraDevice cameraDevice = CameraDevice.Instance;

        // Reallocate the data container if the number of requested images has
        // changed, or if the container is not allocated
        if (mNumImageHeaders != cameraDevice.GetAllImages().Count ||
            (cameraDevice.GetAllImages().Count > 0 && mImageHeaderData == IntPtr.Zero))
        {
            mNumImageHeaders = cameraDevice.GetAllImages().Count;

            Marshal.FreeHGlobal(mImageHeaderData);
            mImageHeaderData = Marshal.AllocHGlobal(Marshal.SizeOf(
                                                        typeof(ImageHeaderData)) * mNumImageHeaders);
        }

        // Update the image info:
        int i = 0;

        foreach (Image image in cameraDevice.GetAllImages().Values)
        {
            IntPtr imagePtr = new IntPtr(mImageHeaderData.ToInt32() + i *
                                         Marshal.SizeOf(typeof(ImageHeaderData)));

            ImageHeaderData imageHeader = new ImageHeaderData();
            imageHeader.width        = image.Width;
            imageHeader.height       = image.Height;
            imageHeader.stride       = image.Stride;
            imageHeader.bufferWidth  = image.BufferWidth;
            imageHeader.bufferHeight = image.BufferHeight;
            imageHeader.format       = (int)image.PixelFormat;
            imageHeader.reallocate   = 0;
            imageHeader.updated      = 0;
            imageHeader.data         = image.UnmanagedData;

            Marshal.StructureToPtr(imageHeader, imagePtr, false);
            ++i;
        }
    }