- private static void HObject2ColoredBitmap(HObject image, out Bitmap res)
- {
- try
- {
- 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);
- int imglength = width * height;
- unsafe
- {
- byte* bptr = (byte*)bitmapData.Scan0;
- byte* r = ((byte*)hred.I); //((byte*)hred.L);
- byte* g = ((byte*)hgreen.I); // ((byte*)hgreen.L);
- byte* b = ((byte*)hblue.I); //((byte*)hblue.L);
- for (int i = 0; i < imglength; 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);
- }
- catch (Exception ex)
- {
- res = null;
- throw ex;
- }
- }
复制代码 |