【发布时间】:2020-09-20 00:38:08
【问题描述】:
我发现自己通过执行以下操作将 1D 字节和单个数组转换为 2D。我怀疑它可能和其他方法一样快,但也许有更简洁的范例? (林克?)
private static byte[,] byte2D(byte[] input, int height, int width)
{
byte[,] output = new byte[height, width];
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
output[i, j] = input[i * width + j];
}
}
return output;
}
private static Single[,] single2D(byte[] input, int height, int width)
{
Single[,] output = new Single[height, width];
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
output[i, j] = (Single)input[i * width + j];
}
}
return output;
}
【问题讨论】:
-
你的第二种方法,是
input的类型应该是byte[]吗? -
您能否提供其中一项功能的示例输入/输出?