public void accessHi3DRange(buffer)
{
double meanR = 0;
uint sumR = 0;
uint countR = 0;
int numberOfScansR = buffer.Height;
bitmapHeight = numberOfScansR;
int subCompWidth = buffer.Components["Hi3D 1"].SubComponents["Range"].Format.Width;
bitmapWidth = subCompWidth;
ushort[,] data = buffer.Components["Hi3D 1"].SubComponents["Range"].GetRows<ushort>(0, numberOfScansR);
for (int scan = 0; scan < numberOfScansR; scan++)
{
for (int col = 0; col < subCompWidth; col++)
{
ushort val = data[scan, col];
if (val != 0)
{
sumR += val;
drawPix(col, scan, (int)val, (int)val, (int)val);
countR++;
}
}
}
}
private void drawPix(int x, int y, int r, int g, int b)
{
((Bitmap)pictureBox1.Image).SetPixel(x, y, Color.FromArgb(r, g, b));
return;
}
当我运行我得到的代码时
System.ArgumentException:'655' 的值对'red' 无效。'red' 应大于或等于 0 且小于或等于 255。
所以为了解决这个错误,我想将ushort
值转换成byte
,以便它可以显示在图片框中。如果是这样,我该如何转换?