public void SetCallBackMessage(ref ImageProperty imageProp, uint pixelAvg) { CurrentImageProperty = imageProp; PixelAverage = pixelAvg; _callbackCount++; CallBackMessageLabel1.Text = "Frame Count:" + _callbackCount + "Exposure Time: " + (CurrentImageProperty.ExposureTime / 20) + "(ms) Pixel Average:" + PixelAverage; // ShowMessage CallBackMessageLabel2.Text = "Row:" + CurrentImageProperty.Row + " Column:" + CurrentImageProperty.Column + " Bin:" + CurrentImageProperty.Bin + " AT(" + CurrentImageProperty.XStart + "," + CurrentImageProperty.YStart + ")"; CallBackMessageLabel3.Text = "Gain: (" + CurrentImageProperty.RedGain + "," + CurrentImageProperty.GreenGain + "," + CurrentImageProperty.BlueGain + ")"; }
// JTZ: The frame callback. public void GrabbingFrameCallback(ref ImageProperty frameProperty, IntPtr SSClassicferPtr) { uint i, pixelAvg; pixelAvg = 0; MightexCam.SetCallBackMessage(ref frameProperty, pixelAvg); // System.Drawing.Imaging.PixelFormat imageFormat = System.Drawing.Imaging.PixelFormat.Format8bppIndexed; System.Drawing.Imaging.PixelFormat imageFormat = System.Drawing.Imaging.PixelFormat.Format24bppRgb; int imageWidth = frameProperty.Column / (frameProperty.Bin + 1); int imageHeight = frameProperty.Row / (frameProperty.Bin + 1); int imageStride; imageStride = imageWidth * 1; imageStride += (imageStride % 4); imageStride *= 3; unsafe { byte *dptr = (byte *)_pImage; byte *sptr = (byte *)SSClassicferPtr; // For Mono camera, the returned image data is 1 byte for each pixel. for (i = 0; i < (imageWidth * imageHeight); i++) { *dptr++ = *sptr; *dptr++ = *sptr; *dptr++ = *sptr++; } } //Bitmap imageBitmap = new Bitmap(imageWidth, imageHeight, imageStride, imageFormat, new IntPtr(SSClassicferPtr)); Bitmap imageBitmap = new Bitmap(imageWidth, imageHeight, imageStride, imageFormat, _pImage); //imageBitmap.RotateFlip(RotateFlipType.Rotate180FlipY); MightexCam.pictureBox1.Image = imageBitmap; }
// JTZ: The frame callback. public void GrabbingFrameCallback(int FrameType, int Row, int Col, ref ImageProperty frameProperty, IntPtr BufferPtr) { uint i, pixelAvg=0; uint frameSize; int notCurrent = (current==0)?1:0; g = Graphics.FromImage(bmps[notCurrent]); g.DrawImage(bmps[current], 0, 0, rect, GraphicsUnit.Pixel); Bmpdata = bmps[current].LockBits(new Rectangle(0, 0, picBox.Width, picBox.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); unsafe { ushort* frameptr; byte* Bmpptr = (byte*)(Bmpdata.Scan0) + pos; byte* bufPtr = null; if(true == hasBuffer) bufPtr = (byte*)(Bufferdata.Scan0) + Bufferdata.Stride*index; /* * JTZ: In tihs example, we get "Raw" data. */ pixelAvg = 0; frameSize = (uint)(Row * Col); // We take 1304 as example, it's 3648 frameptr = (ushort*)BufferPtr; // faster to request memory block copy ? for (i = 0; i < frameSize; i++) { pixelAvg += (uint)*frameptr; byte p = (byte)((uint)*frameptr >> 4); // preview if (i % 10 == 0) { *Bmpptr = p; Bmpptr++; *Bmpptr = p; Bmpptr++; *Bmpptr = p; Bmpptr += (Bmpdata.Stride-2); } // write to buffer if (true == hasBuffer) *bufPtr = p; bufPtr++; // increment source frameptr++; } if (true == mode) // buffer mode index++; pixelAvg = pixelAvg / frameSize; } // stick it in the picture box !!! bmps[current].UnlockBits(Bmpdata); picBox.Image = (Image)bmps[current]; current = notCurrent; /* * JTZ: For Buffer camera, the callback in invoked in the main thread of the application, so it's * allowed to do any GUI operations here...however, don't block here. */ MightexCam.SetCallBackMessage(ref frameProperty, pixelAvg); if (true == hasBuffer && index >= lastIndex) { hasBuffer = false; if (true == mode) buffer.UnlockBits(Bufferdata); bool success = MightexCam.saveBitmap(buffer); // stop if buffered mode or failed to save if (true == mode || false==success) { deallocBitmap(); } else // saved ok and run-on mode { index = 0; hasBuffer = true; // keep going for run-on mode } } }
public void SetCallBackMessage( ref ImageProperty imageProp, uint pixelAvg ) { CurrentImageProperty = imageProp; PixelAverage = pixelAvg; _callbackCount++; CallBackMessageLabel1.Text = "Frame Count:" + _callbackCount + " Exposure Time: " + (CurrentImageProperty.ExposureTime/10) + "(ms)"; // ShowMessage CallBackMessageLabel2.Text = "TimeStamp: " + CurrentImageProperty.TimeStamp; CallBackMessageLabel3.Text = "Pixel Average:" + PixelAverage + " ShieldPixel: " + CurrentImageProperty.LightShieldAverageValue ; }