|
楼主 |
发表于 2022-12-20 09:56:43
|
显示全部楼层
Bot:
/// </summary>
/// <param name="ho_Image">HObject图像</param>
/// <returns>Bitmap图像</returns>
public static Bitmap HObjectToBitmap(HObject ho_Image)
{
Bitmap bmpImage = null;
HObject ho_R, ho_G, ho_B;
HOperatorSet.GenEmptyObj(out ho_R);
HOperatorSet.GenEmptyObj(out ho_G);
HOperatorSet.GenEmptyObj(out ho_B);
HTuple hv_Width, hv_Height;
HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
HOperatorSet.Decompose3(ho_Image, out ho_R, out ho_G, out ho_B);
byte[] bR = new byte[hv_Width * hv_Height];
byte[] bG = new byte[hv_Width * hv_Height];
byte[] bB = new byte[hv_Width * hv_Height];
HOperatorSet.GetGrayval(ho_R, out bR);
HOperatorSet.GetGrayval(ho_G, out bG);
HOperatorSet.GetGrayval(ho_B, out bB);
bmpImage = new Bitmap(hv_Width.I, hv_Height.I, PixelFormat.Format24bppRgb);
Rectangle rect = new Rectangle(0, 0, hv_Width.I, hv_Height.I);
BitmapData bmpData = bmpImage.LockBits(rect, ImageLockMode.ReadWrite, bmpImage.PixelFormat);
IntPtr ptr = bmpData.Scan0;
int bytes = bmpData.Stride * bmpImage.Height;
byte[] rgbValues = new byte[bytes];
for (int i = 0; i < hv_Height.I; i++)
{
for (int j = 0; j < hv_Width.I; j++)
{
rgbValues[(i * bmpData.Stride) + (j * 3)] = bB[i * hv_Width.I + j];
rgbValues[(i * bmpData.Stride) + (j * 3) + 1] = bG[i * hv_Width.I + j];
rgbValues[(i * bmpData.Stride) + (j * 3) + 2] = bR[i * hv_Width.I + j];
}
}
System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes);
bmpImage.UnlockBits(bmpData);
ho_R.Dispose();
ho_G.Dispose();
ho_B.Dispose();
return bmpImage;
}
}
} |
|