What is the mistake in converting a byte array to bitmap in android? (the byte array is sent from a c/c++ server, android beeing the client) -
i'm developing android app sends it's accelerometer , gravity sensor data c/c++ server uses opengl library make 3d shape rotate on screen. want send android device "snapshots" opengl screen.
on c/c++ (server side ) :
//declarations struct params { unsigned char pic[4*256*256]; // 4 because of gl_rgba format char* msg; }; params p; // reading content of screen glreadpixels(0, 0, 256, 256, gl_rgba, gl_unsigned_byte, p.pic); //sending data send(sconnect,(char*)p.pic,4*256*256,0);
on android (client side) i'm trying read byte array , converting bitmap.
//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 sent server datainputstream.readfully(image, 0, 256 * 256 * 4); // //transform byte array int array // i'm doing byte & 0xff convert byte unsigned byte( java doesn't have unsigned byte) // i'm doing convert gl_rgba argb_8888 (int = 1; < image.length; = + 4) { int j = - 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 bitmap: bitmap bmp = bitmap.createbitmap(256, 256, config.argb_8888); bmp.setpixels(intimage, 0, 256, 0, 0, 256, 256); //creating image based on bitmap imv = (imageview) findviewbyid(r.id.imageview1); imv.setimagebitmap(bmp);
in case output blank ( image transparent pixels)
if :
bmp = bitmapfactory.decodebytearray(image, 0,image.length);
the bmp
variable null.
any ideas of wrong?
i think have common endianness problem.
while using glreadpixels on little-endian or big-endian processor results different.
please notice java uses network byte order (big endian). same code written in c++ behaves different on powerpc, arm (big endian) , x86_64 (little endian).
Comments
Post a Comment