将int [] argb转换为byte [] argb [英] convert int[] argb to byte[] argb

查看:87
本文介绍了将int [] argb转换为byte [] argb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何将int [] argb转换为byte [] argb?

how i can convert int[] argb to byte[] argb ?

推荐答案

您可以使用:
You can use:
byte[] BitConverter.GetBytes(int)



使用LINQ扩展:



Using LINQ extensions:

int[] input;
byte[] output = input.SelectMany(i => BitConverter.GetBytes(i)).ToArray();


嘿,

您是否至少已经在Google搜索中看到C#中整数的大小?整数是有符号的32位值.换句话说,1个int = 4个字节.
Hey there,

Have you been at least Googling to see the size of an integer in C#? An integer is a signed 32-bit value. In other words, 1 int = 4 bytes.
int[] data = {123, 321423,3950024, 2385704, 9759023,48634, 987653,6456895,46985589};
byte[] result = Array.ConvertAll(data, intValue => Convert.ToByte(intValue));


当然,如果您使用的是C#3.5或更高版本,则可以调整此代码行.

但是需要注意的重要一点是,Convert.ToByte方法将32位整数转换为8位整数,我希望我不必指出会导致什么.

希望对您有所帮助


Of course, you can tweak this line of code if you are using C#3.5 or above.

But one important thing to note is that, Convert.ToByte method converts a 32-bit integer to an 8-bit integer, and I hope I don''t need to point out what that would result.

Hope this helps, regards


这篇关于将int [] argb转换为byte [] argb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆