问题描述
我正在通过Ethernet
接收比特流.我正在收集Java
中byte[]
数组中的位(我将它们收集在byte []中,因为我认为它是相关的).流是数字化图像,其中每10位代表一个像素.有1280*1024
个像素.每个像素由10位表示.因此,1280*1024*10 = 13107200 bits = 1638400 bytes
是图像大小.
I am receiving a stream of bits over the Ethernet
. I am collecting the bits in a byte[]
array in Java
(I am collecting them in a byte[] because I think its relevant).The stream is a digitized image where every 10 bits represent a pixel. There are 1280*1024
pixels. Every pixel is represented by 10 bits. Hence,1280*1024*10 = 13107200 bits = 1638400 bytes
is the image size.
推荐答案
这里是一种方法,可以采用字节数组并将其拆分"为10位的组.每个组都保存为一个整数.
Here is a method that can take a byte array and "split" it into groups of 10 bit. Each group is saved as an int.
static int[] getPixel(byte[] in) {
int bits = 0, bitCount = 0, posOut = 0;
int[] out = new int[(in.length * 8) / 10];
for(int posIn = 0; posIn < in.length; posIn++) {
bits = (bits << 8) | (in[posIn] & 0xFF);
bitCount += 8;
if(bitCount >= 10) {
out[posOut++] = (bits >>> (bitCount - 10)) & 0x3FF;
bitCount -= 10;
}
}
return out;
}
这篇关于如何用Java将二进制图像数据转换为jpg文件,其中二进制数据中的每10位代表一个像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!