将C#的bitmap格式转换为Halcon的图像格式

       /// <summary>
        /// Bitmap转HObject灰度图
        /// </summary>
        /// <param name="bmp">Bitmap图像</param>
        /// <param name="image">HObject图像</param>
        public static void Bitmap2HObjectBpp8(Bitmap bmp, out HObject image)
        {
            try
            {
                Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
 
                BitmapData srcBmpData = bmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
 
                HOperatorSet.GenImage1(out image, "byte", bmp.Width, bmp.Height, srcBmpData.Scan0);
                bmp.UnlockBits(srcBmpData);
            }
            catch (Exception)
            {
                image = null;
            }
        }

 

posted @ 2021-06-20 11:55  WellMandala  阅读(1206)  评论(0编辑  收藏  举报