protected virtual void OnDalsaImageArrivedHandle(ImgBytesInfo img) { if (DalsaImageArrivedHandle != null) { DalsaImageArrivedHandle(img); } }
private void xfer_XferNotify(object sender, SapXferNotifyEventArgs argsNotify) { try { var core = argsNotify.Context as DalsaCore; if (argsNotify.Trash) { } else { //DateTime getStart = DateTime.Now; IntPtr bufferAddress; Buffers.GetAddress(out bufferAddress); Debug.WriteLine(_name + "Dalsa ImgPtr:[" + _id + "]" + bufferAddress + DateTime.Now); var imgInfo = new ImgBytesInfo(); imgInfo._imgSrcPtr = bufferAddress; imgInfo._imgBytes = new byte[ObjSize]; imgInfo._imgTicks = DateTime.Now.Ticks / 10000; Marshal.Copy(bufferAddress, imgInfo._imgBytes, 0, ObjSize); OnDalsaImageArrivedHandle(imgInfo); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
//mode 1:ImgBytesInfo 2:ImgBitmapInfo private void _core_DalsaImageArrivedHandle(ImgBytesInfo img) { if (_imgInfoType == 1) { img._imgWidth = ImgWidth; img._imgHeight = ImgHeight; img._imgBitDepth = ImgBitDepth; //ImgBytesInfoQ.Enqueue(img); if (_notifyFlag && OnImgArrived != null) { OnImgArrived(img); } } else if (_imgInfoType == 2) { //Bytes turn to Bitmap var imgBitmap = new ImgBitmapInfo(); imgBitmap._imgWidth = ImgWidth; imgBitmap._imgHeight = ImgHeight; imgBitmap._imgBitDepth = ImgBitDepth; imgBitmap._imgTicks = img._imgTicks; var size = new Size(); size.Width = ImgWidth; size.Height = ImgHeight; imgBitmap._bitmap = ImgCommonHelper.MemoryShareToImage(img._imgBytes, size, ImgBitDepth); //ImgBitmapInfoQ.Enqueue(imgBitmap); if (_notifyFlag && OnImgArrived != null) { OnImgArrived(imgBitmap); } } }