| | |
| | | NewImageSet(set); |
| | | OnHImageOutput?.BeginInvoke(this, hImage, set.Id, null, null); |
| | | |
| | | HikToBitmap(nWidth, nHeight, pData, set.Id); |
| | | Generate8GrayImageByPointer(nWidth, nHeight, pData, set.Id); |
| | | } |
| | | else |
| | | { |
| | |
| | | uint nHeight = pFrameInfo.nHeight; |
| | | |
| | | //HikToBitmap(pFrameInfo, frameInfo.pBufAddr); |
| | | HikToBitmap((int)nWidth, (int)nHeight, frameInfo.pBufAddr, ""); |
| | | Generate8GrayImageByPointer((int)nWidth, (int)nHeight, frameInfo.pBufAddr, ""); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | public override ImageSet Snapshot(IOperationConfig config) |
| | | public override IImageSet Snapshot(IOperationConfig config) |
| | | { |
| | | ImageSet set = base.Snapshot(config); |
| | | ImageSet set = new ImageSet(); |
| | | InitialImageSet(set, (config as CameraOprerationConfigBase).ImageSaveOption); |
| | | |
| | | MyCamera.MV_FRAME_OUT frameInfo = new MyCamera.MV_FRAME_OUT(); |
| | | nRet = MyCamera.MV_OK; |
| | | |
| | |
| | | |
| | | set.HImage = hImage; |
| | | |
| | | HikToBitmap((int)nWidth, (int)nHeight, frameInfo.pBufAddr, set.Id); |
| | | Generate8GrayImageByPointer((int)nWidth, (int)nHeight, frameInfo.pBufAddr, set.Id); |
| | | return set; |
| | | } |
| | | } |
| | | } |
| | | |
| | | throw new Exception($"Grap Image Failed:{nRet:x8}"); |
| | | } |
| | | |
| | | [DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)] |
| | | public static extern void CopyMemory(IntPtr dest, IntPtr src, uint count); |
| | | |
| | | private async void HikToBitmap(int width, int height, IntPtr dataPtr, string imgSetId) |
| | | { |
| | | await Task.Run(() => |
| | | { |
| | | //************************Mono8 转 Bitmap******************************* |
| | | Bitmap bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed); |
| | | Bitmap showImage = new Bitmap(width, height, PixelFormat.Format8bppIndexed); |
| | | |
| | | ColorPalette cp = bmp.Palette; |
| | | for (int i = 0; i < 256; i++) |
| | | { |
| | | cp.Entries[i] = Color.FromArgb(i, i, i); |
| | | } |
| | | bmp.Palette = cp; |
| | | |
| | | ColorPalette cp1 = showImage.Palette; |
| | | for (int i = 0; i < 256; i++) |
| | | { |
| | | cp1.Entries[i] = Color.FromArgb(i, i, i); |
| | | } |
| | | showImage.Palette = cp1; |
| | | |
| | | int[] ptr = new int[3]; |
| | | Rectangle rect = new Rectangle(0, 0, width, height); |
| | | BitmapData bitmapData = bmp.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); |
| | | BitmapData showImageData = showImage.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); |
| | | int PixelSize = Bitmap.GetPixelFormatSize(bitmapData.PixelFormat) / 8; |
| | | |
| | | if (width % 4 == 0) |
| | | { |
| | | CopyMemory(bitmapData.Scan0, dataPtr, (uint)(width * height * PixelSize)); |
| | | CopyMemory(showImageData.Scan0, dataPtr, (uint)(width * height * PixelSize)); |
| | | } |
| | | else |
| | | { |
| | | ptr[0] = bitmapData.Scan0.ToInt32(); |
| | | ptr[1] = showImageData.Scan0.ToInt32(); |
| | | ptr[2] = (int)dataPtr; |
| | | for (int i = 0; i < height - 1; i++) |
| | | { |
| | | ptr[2] += width; |
| | | |
| | | CopyMemory((IntPtr)ptr[0], (IntPtr)ptr[2], (uint)(width * PixelSize)); |
| | | CopyMemory((IntPtr)ptr[1], (IntPtr)ptr[2], (uint)(width * PixelSize)); |
| | | ptr[0] += bitmapData.Stride; |
| | | ptr[1] += showImageData.Stride; |
| | | } |
| | | } |
| | | bmp.UnlockBits(bitmapData); |
| | | showImage.UnlockBits(showImageData); |
| | | |
| | | SaveOriginImage(bmp, showImage, imgSetId); |
| | | }); |
| | | } |
| | | |
| | | readonly MyCamera device = new MyCamera(); |
| | |
| | | { |
| | | if (nMsgType == MyCamera.MV_EXCEPTION_DEV_DISCONNECT) |
| | | { |
| | | Thread.Sleep(1000); |
| | | |
| | | Stop(); |
| | | |
| | | if (CurrentState != EnumHelper.DeviceState.DSClose) |
| | | { |
| | | int reTryTimes = 3; |
| | | do |
| | | { |
| | | Thread.Sleep(1000); |
| | | Stop(); |
| | | |
| | | try |
| | | { |
| | | Start(); |
| | |
| | | if (reTryTimes > 0) |
| | | { |
| | | //OnLog?.Invoke(DateTime.Now, this, "重新连接相机异常\r\n" + ex.GetExceptionMessage()); |
| | | LogAsync(DateTime.Now, "重新连接异常", ex.GetExceptionMessage()); |
| | | LogAsync(DateTime.Now, $"{this.Name}重新连接异常", ex.GetExceptionMessage()); |
| | | } |
| | | else |
| | | { |