Halcon对象Hobject转换为.net对象Bitmap
来源:互联网 发布:网络摄像头平台 编辑:程序博客网 时间:2024/06/12 02:08
好多年不写了,这几天做项目遇到个烦死的问题,大周末的终于解决了。
用Halcon转换成C#时 Hobject对象如何转换成我们认识的Bitmap呢,搞了两天终于好了。
上代码。麻麻再也不用担心我的转换问题了。
private void GenertateGrayBitmap(HObject image, out Bitmap res) { HTuple hpoint, type, width, height; const int Alpha = 255; int[] ptr = new int[2]; HOperatorSet.GetImagePointer1(image, out hpoint, out type, out width, out height); res = new Bitmap(width, height, PixelFormat.Format8bppIndexed); ColorPalette pal = res.Palette; for (int i = 0; i <= 255; i++) { pal.Entries[i] = Color.FromArgb(Alpha, i, i, i); } res.Palette = pal; Rectangle rect = new Rectangle(0, 0, width, height); BitmapData bitmapData = res.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); int PixelSize = Bitmap.GetPixelFormatSize(bitmapData.PixelFormat) / 8; ptr[0] = bitmapData.Scan0.ToInt32(); ptr[1] = hpoint.I; if (width % 4 == 0) CopyMemory(ptr[0], ptr[1], width * height * PixelSize); else { for (int i = 0; i < height - 1; i++) { ptr[1] += width; CopyMemory(ptr[0], ptr[1], width * PixelSize); ptr[0] += bitmapData.Stride; } } res.UnlockBits(bitmapData); } private void GenertateRGBBitmap(HObject image, out Bitmap res) { HTuple hred, hgreen, hblue, type, width, height; HOperatorSet.GetImagePointer3(image, out hred, out hgreen, out hblue, out type, out width, out height); res = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppRgb); Rectangle rect = new Rectangle(0, 0, width, height); BitmapData bitmapData = res.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb); unsafe { byte* bptr = (byte*)bitmapData.Scan0; byte* r = ((byte*)hred.I); byte* g = ((byte*)hgreen.I); byte* b = ((byte*)hblue.I); for (int i = 0; i < width * height; i++) { bptr[i * 4] = (b)[i]; bptr[i * 4 + 1] = (g)[i]; bptr[i * 4 + 2] = (r)[i]; bptr[i * 4 + 3] = 255; } } res.UnlockBits(bitmapData); }
1 1
- Halcon对象Hobject转换为.net对象Bitmap
- .net 中Bitmap和Halcon中HObject的相互转换
- OpenCV数据格式转换成Halcon数据格式HObject
- 将一个view对象转换为bitmap对象
- 将DIB/bitmap读入内存并转为 halcon hobject
- 获取View的截图-将View转换为Bitmap对象
- OpenCV的Mat和Halcon的HObject类型互相转换
- 将.Net对象转换为Json字符串
- 设置bitmap的宽高,同时将bitmap转换为file对象
- byte图片转halcon,hobject
- Halcon 里Hobject 转HImage
- 转换为const 对象
- 对象转换为Map
- json转换为对象
- 把 view 转换成bitmap对象
- 将view对象转化为Bitmap
- 将view对象转化为Bitmap
- 读取图片资源转化为bitmap对象
- Struts2标签—Iterator标签
- 浅谈JSONP跨域请求
- How to enable virtualization on Thinkpad X1 Carbon with Win10 installed
- 【Java】接口和抽象类的区别
- 黑马程序员---Java基础加强---JDK1.5新特性:注解
- Halcon对象Hobject转换为.net对象Bitmap
- Android中shape的使用
- 【bzoj1925】【SCOI2009】【最长距离】【spfa】
- XML解析的两种方式:DOM方式和SAX方式
- random_shuffle函数改变vector容器中元素的次序
- 算术表达式的计算(基于逆波兰表达式)的c++实现
- 项目中ibatis的isNotNull和isNotEmpty区别
- hadoop查询一条数据
- 面试准备:java Thread详解