下面代码是我在搜索 get_image_pointer1 过程中得到,给我带来了一些灵感。
- /// <summary>
- /// 灰度图像变量 HObject -> Bitmap
- /// 原文:[url=https://blog.csdn.net/bingbingxie1/article/details/83344704]https://blog.csdn.net/bingbingxie1/article/details/83344704[/url]
- /// </summary>
- public static Bitmap HObject2Bitmap(HObject ho)
- {
- try
- {
- HTuple type, width, height, pointer;
- //HOperatorSet.AccessChannel(ho, out ho, 1);
- HOperatorSet.GetImagePointer1(ho, out pointer, out type, out width, out height);
- //himg.GetImagePointer1(out type, out width, out height);
- Bitmap bmp = new Bitmap(width.I, height.I, PixelFormat.Format8bppIndexed);
- ColorPalette pal = bmp.Palette;
- for (int i = 0; i <= 255; i++)
- {
- pal.Entries[i] = Color.FromArgb(255, i, i, i);
- }
- bmp.Palette = pal;
- BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
- int PixelSize = Bitmap.GetPixelFormatSize(bitmapData.PixelFormat) / 8;
- int stride = bitmapData.Stride;
- int ptr = bitmapData.Scan0.ToInt32();
- for (int i = 0; i < height; i++)
- {
- CopyMemory(ptr, pointer, width * PixelSize);
- pointer += width;
- ptr += bitmapData.Stride;
- }
- bmp.UnlockBits(bitmapData);
- return bmp;
- }
- catch (Exception exc)
- {
- return null;
- }
- }
- /// <summary>
- /// 灰度图像变量 HObject -> HImage
- /// 原文:[url=https://blog.csdn.net/pudongdong/article/details/53574742]https://blog.csdn.net/pudongdong/article/details/53574742[/url]
- /// </summary>
- public HImage HObject2HImage(Hobject hobject)
- {
- HImage image;
- HTuple type, width, height, pointer;
- gHOperatorSet.GetImagePointer1(ho, out pointer, out type, out width, out height);
- image.GenImage1(type, width, height, pointer);
- return image;
- }
复制代码 |