| | |
| | | private void OnAcquisitionCompleted(IntPtr pInstance, int nOption) |
| | | { |
| | | // nOption: 0=一批数据结束, 1=全部完成, 2=点云就绪 |
| | | // 根据需求变更,我们只处理亮度图。Option 1 或 0 表示 2D 数据就绪。 |
| | | if (nOption == 1 || nOption == 0) |
| | | { |
| | | GenerateBitmapAndNotify(); |
| | | GenerateIntensityMap(); |
| | | } |
| | | } |
| | | |
| | | private void GenerateBitmapAndNotify() |
| | | private void GenerateIntensityMap() |
| | | { |
| | | Bitmap bmp = null; |
| | | lock (_bufferLock) |
| | | if (_cameraHandle == IntPtr.Zero) return; |
| | | |
| | | int width = 0; |
| | | int height = 0; |
| | | |
| | | // 直接从 SDK 获取合并后的强度数据指针 (unsigned char*) |
| | | IntPtr pIntensity = PHM6000Profiler.GetIntensityData(_cameraHandle, ref width, ref height); |
| | | |
| | | if (pIntensity == IntPtr.Zero || width <= 0 || height <= 0) return; |
| | | |
| | | try |
| | | { |
| | | if (_lineDataBuffer.Count == 0) return; |
| | | |
| | | // 默认宽度 4096 (线扫传感器典型值) |
| | | int width = 4096; |
| | | int height = _lineDataBuffer.Count; |
| | | |
| | | bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed); |
| | | Bitmap bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed); |
| | | |
| | | // 设置灰度调色板 |
| | | ColorPalette palette = bmp.Palette; |
| | |
| | | |
| | | BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); |
| | | |
| | | IntPtr scan0 = bmpData.Scan0; |
| | | for (int i = 0; i < height; i++) |
| | | { |
| | | // 仅提取 Alpha (强度图) |
| | | // 注意:LBPointZA 结构中 alpha 是第 8 个字节 |
| | | byte[] lineBytes = _lineDataBuffer[i]; |
| | | byte[] intensityRow = new byte[width]; |
| | | |
| | | for (int x = 0; x < Math.Min(width, lineBytes.Length / 8); x++) |
| | | { |
| | | intensityRow[x] = lineBytes[x * 8 + 7]; // alpha 位 |
| | | } |
| | | |
| | | Marshal.Copy(intensityRow, 0, scan0 + (i * bmpData.Stride), width); |
| | | } |
| | | // 高性能内存拷贝 |
| | | int size = width * height; |
| | | byte[] managedData = new byte[size]; |
| | | Marshal.Copy(pIntensity, managedData, 0, size); |
| | | Marshal.Copy(managedData, 0, bmpData.Scan0, size); |
| | | |
| | | bmp.UnlockBits(bmpData); |
| | | _lineDataBuffer.Clear(); |
| | | } |
| | | |
| | | if (bmp != null) |
| | | { |
| | | // 触发事件 |
| | | // 触发事件通知 UI 更新亮度图 |
| | | ImageGrabbed?.Invoke(this, new CameraEventArgs(SN, bmp)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | AsyncLogHelper.Error($"PHM6000: 生成亮度图异常 - {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | private void SyncConfigFromCamera() |