在android中将字节数组转换为位图有什么错误?(字节数组是从c/c+;+;服务器发送的,android正在运行客户端)

在android中将字节数组转换为位图有什么错误?(字节数组是从c/c+;+;服务器发送的,android正在运行客户端),android,c,sockets,opengl-es,Android,C,Sockets,Opengl Es,我正在开发一个android应用程序,它将加速度计和重力传感器数据发送到一个c/c++服务器,该服务器使用openGL库在屏幕上旋转3D形状。我想将OpenGL屏幕上的“快照”发送回android设备 在c/c++(服务器端)上,我执行以下操作: //declarations struct PARAMS { unsigned char Pic[4*256*256]; // 4 because of the GL_RGBA format char* msg; }; PARA

我正在开发一个android应用程序,它将加速度计和重力传感器数据发送到一个c/c++服务器,该服务器使用openGL库在屏幕上旋转3D形状。我想将OpenGL屏幕上的“快照”发送回android设备

在c/c++(服务器端)上,我执行以下操作:

//declarations
    struct PARAMS
{
    unsigned char Pic[4*256*256]; // 4 because of the GL_RGBA format
    char* msg;
};
PARAMS p;

// reading content of the screen
glReadPixels(0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, p.Pic);

//sending the data
send(sConnect,(char*)p.Pic,4*256*256,0);
bmp = BitmapFactory.decodeByteArray(Image, 0,Image.length);
在android(客户端)上,我试图读取字节数组并将其转换为位图

//declarations
socket = new Socket("192.168.1.101", 1234);
dataOutputStream = new DataOutputStream(socket.getOutputStream());
private byte Image[]=  new byte[4 * 256 * 256 ];
private int IntImage[] = new int[4 * 256 * 256];
//read data which was sent from the server
dataInputStream.readFully(Image, 0, 256 * 256 * 4); // 



  //transform the byte array into int array
    // i'm doing byte & 0xFF to convert from byte to unsigned byte( java doesn't have unsigned           Byte)
    // I'm doing this to convert from GL_RGBA to ARGB_8888
    for (int i = 1; i < Image.length; i = i + 4) {
        int j = i - 1;
        aux = (Image[i + 3] & 0xFF);
        IntImage[j + 3] = (int) (Image[i + 2] & 0xFF);
        IntImage[j + 2] = (int) (Image[i + 1] & 0xFF);
        IntImage[j + 1] = (int) (Image[i] & 0xFF);
        IntImage[j] = aux;
 }

 //creating the bitmap:
 Bitmap bmp = Bitmap.createBitmap(256, 256, Config.ARGB_8888);
 bmp.setPixels(IntImage, 0, 256, 0, 0, 256, 256);

 //creating the image based on the bitmap
 imv = (ImageView) findViewById(R.id.imageView1);
 imv.setImageBitmap(bmp);
bmp
变量将始终为空


你知道我哪里做错了吗?

我想你有共同的endianness问题

在小端处理器或大端处理器上使用glReadPixels时,结果是不同的


请注意Java的用法(big-endian)。用C++编写的相同代码在PowerPC、ARM(大Endiad)和X8664(小字节)上的行为不同。

< p>您将值存储在int类型的数组中。Android格式的ARBBH88 88是一个字节数组,每个像素得到4字节,因此“8888”。p> 如果您重写它以逐字节交换值,而不是将字节交换为int,那么它应该可以工作


我最近一直在做类似的工作,我制作了一个包含ARGB_8888数据的文件。(1字节alpha+1字节红色,1字节绿色,1字节蓝色像素的宽度*高度)如果我将其放入资源中,将其读入字节[]数组,并将其复制到正确尺寸的ARGB_8888位图中,它将正确显示

我把我从C++发送的字节数组和我在java/Android中接收到的字节数组转换成int数组,而RESaUT是相同的。(我发送的数据就是我接收的数据)。这还会是一个持久性的问题吗?