using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace CCDCount.DLL { public class LoadSplieImageClass { #region 变量 //读取的图片路径 private string SplieImagePath = ""; //读取到的图像 Bitmap bitmap; #endregion #region 公共方法 public void LoadImage(string ImagePath) { SplieImagePath = ImagePath; bitmap = new Bitmap(ImagePath); } /// /// 读取图像像素信息并分割 /// 目前仅分解海康VM平台保存的二值化BMP文件可正常读取像素信息 /// /// public List SplieImage() { //初始化返回列表数组 List result = new List(); for (int i = 0; i < bitmap.Height; i++) { result.Add(new byte[bitmap.Width]); } //读取全部像素信息 BitmapData data = bitmap.LockBits( new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat ); //分行读取 for (int i = 0; i < bitmap.Height; i++) { Marshal.Copy(IntPtr.Add(data.Scan0, i * bitmap.Width * sizeof(byte)), result[i], 0, bitmap.Width); } bitmap.UnlockBits(data); return result; // 原始字节数据(需根据 PixelFormat 解析) } #endregion } }