- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用 Kinect for Xbox 360 和 SDK 1.8 计算玩家的表面积。我遇到了一个小问题,我需要将 short[]
转换为 int[]
,反之亦然。解释更多...
short[] rawDepthData = new short[depthFrame.PixelDataLength];
depthFrame.CopyPixelDataTo(rawDepthData);
但我需要 int[]
格式的 rawDepthData
..
感谢帮助非常感谢
最佳答案
对于您可能希望尽可能快的事情,您可能需要考虑编写自己的循环以将 short[]
数组复制到新的 int[]
数组,例如:
public static int[] Convert(short[] input)
{
int[] result = new int[input.Length];
for (int i = 0; i < input.Length; ++i)
result[i] = input[i];
return result;
}
这是您转换回来的方式。重要提示:这假设每个 int
值都适合一个 short
。否则,它们将被截断并且值将发生变化!
public static short[] Convert(int[] input)
{
short[] result = new short[input.Length];
unchecked
{
for (int i = 0; i < input.Length; ++i)
result[i] = (short) input[i];
}
return result;
}
(注意:将此代码与 Array.ConvertAll()
的性能进行比较时,您必须将此代码编译为 RELEASE 版本 - 否则您会将调试版本与发布版本进行比较构建。)
关于c# - 将 int[] 转换为 short[],反之亦然,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36842664/
C# 程序: short a, b; a = 10; b = 10; a = a + b; // Error : Cannot implicitly convert type 'int' to 'sh
这个问题已经有答案了: Promotion in Java? (5 个回答) 已关闭10 年前。 我有三个短变量。当我将两个相加并将结果分配给第三个时,Eclipse 告诉我需要将其转换为 Short
我正在开展一个项目,我需要获取一系列带符号的 16 位整数、负值和正值,并将它们发送到函数以在单元测试期间进行分析。 由于不同的原因,该函数仅采用无符号 16 位整数数组,因此我需要将有符号整数存储在
这个问题在这里已经有了答案: Implicit type promotion rules (4 个答案) 关闭 3 年前。 有如下代码: short a = 5; short b = 15; sho
我有以下代码: var v = [0xFF, 0xFF]; alert((v[0]> 16); 16位左移将所有位向左移动;算术 16 位右移在移位时处理符号。 (Javascript 使用 32 位
我正在尝试尽可能多地挤出我的内存。我有一个 4.9999995e13 整数矩阵,但它们只需要为真或假 - 基本上我只需要为这些整数中的每一个存储一位。 我知道 C 中没有单个位类型(也许有人可以向我解
这个问题已经有答案了: Different between parseInt() and valueOf() in java? (11 个回答) 已关闭 5 年前。 我最近偶然发现了another q
当我将相同的值分配给有符号和无符号的 short 并进行比较时,它失败了,但它适用于 int。除非我强制转换一个或另一个使它们成为相同的类型,否则比较不起作用。 #include int main()
所以我试图解释以下输出: short int v = -12345; unsigned short uv = (unsigned short) v; printf("v = %d, uv = %u\n
当我将相同的值分配给有符号和无符号的 short 并进行比较时,它失败了,但它适用于 int。除非我强制转换一个或另一个使它们成为相同的类型,否则比较不起作用。 #include int main()
这个问题在这里已经有了答案: What is the 'short' data type in C? (1 个回答) 关闭 7 年前。 将变量声明为 short int 和 short 有什么区别?
C 中的 short int 包含 16 位,第一位表示该值是负数还是正数。我有一个 C 程序如下: int main() { short int v; unsigned short
Short.parseShort(String s, int radix) 存在,Integer.parseInt(String s, int radix) 和 Long.parseLong(Stri
我想我可以从 this question 推断出来但我不能 我当然可以 short[] shortarray = {0,1,2}; List shortList = new ArrayList();
这个问题在这里已经有了答案: char and the usual arithmetic conversion rules (5 个答案) 关闭 6 年前。 假设 int 是 16 位类型,以防止从
到目前为止我已经试过了,但我仍然在下面的代码中遇到错误: #include typedef unsigned short unichar; typedef const unichar unimap_t
unsigned short int 和 c 中的 unsigned short decleration 之间有区别吗?如果有,那是什么?我尝试在网上查找,但找不到任何有值(value)的东西。 un
我有数据库,由于与另一位开发人员混淆,我需要在一个表中更改列的值。我有一个名为 credits 的表和一个名为 credit_type 的列。 credit_type 有 2 个值 long 和 sh
我在 JNI hell 中进行类型转换: 这是一般的流程: 读取一个文件,它返回一个一维 float 组。 转换这些floats[] 到 shorts[](*4095,我想要一个12位数字) 将这些短
我正在尝试优化两个 c 样式数组的点积,这些数组的大小为 contant 和 small,类型为 short。 我已经阅读了一些关于 SIMD 内在函数的文档以及许多关于使用此内在函数进行点积优化的博
我是一名优秀的程序员,十分优秀!