// Function to initialize a bitmap for the converted image.
        static void InitBitmapStructure(int nRows, int nCols,
                                        ref FlyCaptureImage flycapRGBImage)
        {
            BITMAPINFO bmi    = new BITMAPINFO(); // bitmap header
            byte *     pvBits = null;             //	pointer	to DIB section
            int        nBytes;

            nBytes = nRows * nCols * 3;            // for R,G,B

            bmi.bmiHeader.biSize        = 40;      // sizeof(BITMAPINFOHEADER) = 40
            bmi.bmiHeader.biWidth       = nCols;
            bmi.bmiHeader.biHeight      = nRows;
            bmi.bmiHeader.biPlanes      = 1;
            bmi.bmiHeader.biBitCount    = 24;          // three	8-bit components
            bmi.bmiHeader.biCompression = 0;           //	BI_RGB = 0
            bmi.bmiHeader.biSizeImage   = nBytes;
            CreateDIBSection(null, ref bmi, DIB_RGB_COLORS,
                             ref pvBits, 0, 0);

            // This	is where we	set	the	"to	be converted" image	data pointer
            // to our newly created bitmap data pointer
            flycapRGBImage.pData = pvBits;
        }
示例#2
0
 public static extern int flycaptureConvertImage(int flycapContext,
                                                 ref FlyCaptureImage image, ref FlyCaptureImage imageConvert);
示例#3
0
 unsafe public static extern int flycaptureSaveImage(int flycapContext,
                                                     ref FlyCaptureImage image,
                                                     string filename,
                                                     FlyCaptureImageFileFormat fileFormat);
示例#4
0
 unsafe public static extern int flycaptureGrabImage2(int flycapContext, ref FlyCaptureImage image);
示例#5
0
        static void Main(string[] args)
        {
            int flycapContext;
            int ret;
            FlyCaptureInfoEx flycapInfo     = new FlyCaptureInfoEx();
            FlyCaptureImage  image          = new FlyCaptureImage();
            FlyCaptureImage  flycapRGBImage = new FlyCaptureImage();

            // Create the context.
            ret = flycaptureCreateContext(&flycapContext);
            if (ret != 0) // test
            {
                reportError(ret, "flycaptureCreateContext");
                return;
            }

            // Initialize the camera.
            ret = flycaptureInitialize(flycapContext, _CAMERA_INDEX);
            if (ret != 0)
            {
                reportError(ret, "flycaptureInitialize");
                return;
            }

            // Get the info for this camera.
            ret = flycaptureGetCameraInfo(flycapContext, ref flycapInfo);
            if (ret != 0)
            {
                reportError(ret, "flycaptureGetCameraInformation");
                return;
            }
            if (flycapInfo.CameraType == FlyCaptureCameraType.FLYCAPTURE_BLACK_AND_WHITE)
            {
                Console.Write("Model: B&W " + flycapInfo.pszModelString + "\n"
                              + "Serial #: " + flycapInfo.SerialNumber + "\n");
            }
            else if (flycapInfo.CameraType == FlyCaptureCameraType.FLYCAPTURE_COLOR)
            {
                Console.Write("Model: Colour " + flycapInfo.pszModelString + "\n"
                              + "Serial #: " + flycapInfo.SerialNumber + "\n");
            }

            // Start FlyCapture.
            ret = flycaptureStart(flycapContext,
                                  FlyCaptureVideoMode.FLYCAPTURE_VIDEOMODE_ANY,
                                  FlyCaptureFrameRate.FLYCAPTURE_FRAMERATE_ANY);
            if (ret != 0)
            {
                reportError(ret, "flycaptureStart");
                return;
            }

            // Grab one image to examine the image size
            ret = flycaptureGrabImage2(flycapContext, ref image);
            if (ret != 0)
            {
                reportError(ret, "flycaptureGrabImage2");
                return;
            }

            // Allocate buffer for color processed image
            byte[] BGR_buffer = new byte[image.iRows * image.iCols * 3];

            // Start grabbing images.
            Console.Write("\nGrabbing Images ");
            for (int iImage = 0; iImage < _IMAGES_TO_GRAB; iImage++)
            {
                // grab an image
                ret = flycaptureGrabImage2(flycapContext, ref image);
                if (ret != 0)
                {
                    reportError(ret, "flycaptureGrabImage2");
                    return;
                }

                // Convert the image.
                fixed(byte *pBGR_buffer = BGR_buffer)
                {
                    flycapRGBImage.pData       = pBGR_buffer;
                    flycapRGBImage.pixelFormat = FlyCapturePixelFormat.FLYCAPTURE_BGR;
                    ret = flycaptureConvertImage(flycapContext, ref image, ref flycapRGBImage);
                    if (ret != 0)
                    {
                        reportError(ret, "flycaptureConvertImage");
                        return;
                    }
                }

                Console.Write(".");
            }


            // Save the image.
            Console.Write("\nSaving Last Image ");
            ret = flycaptureSaveImage(flycapContext, ref flycapRGBImage, "color.bmp",
                                      FlyCaptureImageFileFormat.FLYCAPTURE_FILEFORMAT_BMP);
            if (ret != 0)
            {
                reportError(ret, "flycaptureSaveImage");
                return;
            }
            else
            {
                System.Diagnostics.Process.Start("mspaint.exe", "color.bmp");
            }

            // Stop FlyCapture.
            ret = flycaptureStop(flycapContext);
            if (ret != 0)
            {
                reportError(ret, "flycaptureStop");
                return;
            }

            // Destroy the context.
            ret = flycaptureDestroyContext(flycapContext);
            if (ret != 0)
            {
                reportError(ret, "flycaptureDestroyContext");
                return;
            }

            Console.Write("\nPress Enter");
            Console.Read();
        }
		static void Main(string[] args)
		{
			int	flycapContext;
			int	ret;
			FlyCaptureInfo flycapInfo = new FlyCaptureInfo();
			FlyCaptureImage image = new FlyCaptureImage();
			FlyCaptureImage flycapRGBImage = new FlyCaptureImage();

			// Create the context.
			ret	= flycaptureCreateContext(&flycapContext);
			if (ret	!= 0 )
			{
				reportError(ret,"flycaptureCreateContext");
				return;
			}
				
			// Initialize the camera.
			ret = flycaptureInitialize( flycapContext, _CAMERA_INDEX );
			if (ret	!= 0 )
			{
				reportError(ret,"flycaptureInitialize");
				return;
			}

			// Get the info for this camera.
			ret = flycaptureGetCameraInformation( flycapContext, ref flycapInfo );
			if (ret	!= 0 )
			{
				reportError(ret,"flycaptureGetCameraInformation");
				return;
			}
			if (flycapInfo.CameraType == 
				FlyCaptureCameraType.FLYCAPTURE_BLACK_AND_WHITE)
			{
				Console.Write( "Model: B&W " + flycapInfo.pszModelString + "\n"
					+ "Serial #: " + flycapInfo.SerialNumber + "\n");
			}
			else if (flycapInfo.CameraType == 
				FlyCaptureCameraType.FLYCAPTURE_COLOR)
			{
				Console.Write( "Model: Colour " + flycapInfo.pszModelString + "\n"
					+ "Serial #: " + flycapInfo.SerialNumber + "\n");
			}
			
			// Start FlyCapture.
			ret	= flycaptureStart( flycapContext, 
				FlyCaptureVideoMode.FLYCAPTURE_VIDEOMODE_ANY,
				FlyCaptureFrameRate.FLYCAPTURE_FRAMERATE_ANY );
			if (ret	!= 0 )
			{
				reportError(ret,"flycaptureStart");
				return;
			}

			// Start grabbing images.
			Console.Write("\nGrabbing Images ");
			for ( int iImage = 0; iImage < _IMAGES_TO_GRAB; iImage++ )
			{
				ret = flycaptureGrabImage2( flycapContext, ref image );
				if (ret	!= 0 )
				{
					reportError(ret,"flycaptureGrabImage2");
					return;
				}
				Console.Write(".");
			}

			// Convert the image.
			InitBitmapStructure(image.iRows, image.iCols, ref flycapRGBImage );
			flycapRGBImage.pixelFormat = FlyCapturePixelFormat.FLYCAPTURE_BGR;
			ret = flycaptureConvertImage( flycapContext, ref image, 
				ref flycapRGBImage);
			if (ret	!= 0 )
			{
				reportError(ret,"flycaptureConvertImage");
				return;
			}
			
			// Save the image.
			Console.Write("\nSaving Last Image ");
			ret = flycaptureSaveImage( flycapContext, ref flycapRGBImage, "raw.bmp", 
				FlyCaptureImageFileFormat.FLYCAPTURE_FILEFORMAT_BMP );
			if (ret	!= 0 )
			{
				reportError(ret,"flycaptureSaveImage");
				return;
			}
			else
				System.Diagnostics.Process.Start("mspaint.exe", "raw.bmp");

			// Stop FlyCapture.
			ret = flycaptureStop(flycapContext);
			if (ret	!= 0 )
			{
				reportError(ret,"flycaptureStop");
				return;
			}

			// Destroy the context.
			ret = flycaptureDestroyContext(flycapContext);
			if (ret	!= 0 )
			{
				reportError(ret,"flycaptureDestroyContext");
				return;
			}

			Console.Write("\nPress Enter");
			Console.Read();
		}			
		// Function to initialize a bitmap for the converted image.
		static void InitBitmapStructure(int nRows, int nCols, 
			ref FlyCaptureImage flycapRGBImage)
		{

			BITMAPINFO bmi = new BITMAPINFO();	// bitmap header
			byte* pvBits = null; //	pointer	to DIB section
			int	nBytes;

			nBytes = nRows * nCols * 3;	// for R,G,B

			bmi.bmiHeader.biSize = 40; // sizeof(BITMAPINFOHEADER) = 40
			bmi.bmiHeader.biWidth =	nCols;
			bmi.bmiHeader.biHeight = nRows;
			bmi.bmiHeader.biPlanes = 1;
			bmi.bmiHeader.biBitCount = 24; // three	8-bit components
			bmi.bmiHeader.biCompression	= 0; //	BI_RGB = 0
			bmi.bmiHeader.biSizeImage =	nBytes;
			CreateDIBSection(null, ref bmi, DIB_RGB_COLORS, 
				ref pvBits, 0,	0);

			// This	is where we	set	the	"to	be converted" image	data pointer 
			// to our newly created bitmap data pointer
			flycapRGBImage.pData = pvBits;
		}
		public static extern int flycaptureConvertImage(int flycapContext, 
			ref FlyCaptureImage image, ref FlyCaptureImage imageConvert);
		unsafe public static extern int flycaptureSaveImage(int flycapContext, 
			ref FlyCaptureImage image, string filename, 
			FlyCaptureImageFileFormat fileFormat);
		unsafe public static extern int flycaptureGrabImage2(int flycapContext, 
			ref FlyCaptureImage image);