//////////////////////////////////////////////////////////////////////////////// // Update Image. // *Get the current image from the device. // *Create Bitamap data. // void UpdateImage(int cameraIndex) { CamApiStatus status; int bufferIndex = 0; Bitmap bmp = null; BitmapData bitmapData = null; CameraImageInfo imageInfo = null; status = this.arrayCamDevice[cameraIndex].camStream.GetCurrentBufferIndex(out bufferIndex); if ((status != CamApiStatus.Success) || (bufferIndex == -1)) { Console.WriteLine("bufferIndex"); Console.WriteLine("imagenumber = {0}", imagenumber); Console.WriteLine("cameraIndex = {0}", cameraIndex); Console.WriteLine("status : {0}", status); Console.WriteLine("bufferIndex = {0}", bufferIndex); return; } status = this.arrayCamDevice[cameraIndex].camStream.LockBuffer(bufferIndex, ref imageInfo); if (status != CamApiStatus.Success) { Console.WriteLine("status"); Console.WriteLine("imagenumber = {0}", imagenumber); Console.WriteLine("cameraIndex = {0}", cameraIndex); Console.WriteLine("status : {0}", status); return; } try { if (imageInfo.Status != CamApiStatus.Success) { Console.WriteLine("imageInfo"); Console.WriteLine("imagenumber = {0}", imagenumber); Console.WriteLine("cameraIndex = {0}", cameraIndex); Console.WriteLine("imageInfo.Status ; {0}", imageInfo.Status); Terminate(); //return; } // Create Bitmap data. unsafe { if (imageInfo.PixelFormat == CameraPixelFormat.Mono8) { bmp = new Bitmap(imageInfo.SizeX, imageInfo.SizeY, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); // Set palette in bitmap ColorPalette monoPalette = bmp.Palette; for (int i = 0; i <= 255; i++) { monoPalette.Entries[i] = Color.FromArgb(i, i, i); } bmp.Palette = monoPalette; bitmapData = bmp.LockBits(new Rectangle(0, 0, imageInfo.SizeX, imageInfo.SizeY), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); CameraUtility.CopyMemoryT(bitmapData.Scan0, imageInfo.BufferPointer, (imageInfo.SizeX * imageInfo.SizeY)); } else { bmp = new Bitmap(imageInfo.SizeX, imageInfo.SizeY, System.Drawing.Imaging.PixelFormat.Format24bppRgb); bitmapData = bmp.LockBits(new Rectangle(0, 0, imageInfo.SizeX, imageInfo.SizeY), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb); CameraUtility.ConvertImage(DstPixelFormat.BGR24, imageInfo.PixelFormat, true, bitmapData.Scan0, imageInfo.BufferPointer, imageInfo.SizeX, imageInfo.SizeY); } bmp.UnlockBits(bitmapData); } } finally { this.arrayCamDevice[cameraIndex].camStream.UnlockBuffer(bufferIndex); } //DispBitmap(cameraIndex, bmp); PrintBitmap(cameraIndex, bmp); //Console.WriteLine(flag[cameraIndex] ); GC.Collect(); }