私は、加速度計と重力センサーのデータを、openGL ライブラリを使用して画面上で 3D 形状を回転させる ac/c++ サーバーに送信する Android アプリを開発しています。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);
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 = BitmapFactory.decodeByteArray(Image, 0,Image.length);
bmp
変数は常に null になります。
私が間違っている場所のアイデアはありますか?