开发者

Android camera preview byte[] to Java image

I have an android app which uses camera. I am using a socket connection to send the byte[] of onPreviewFrame() of the camera.

Here is my code

public void onPreviewFrame(byte[] data, Camera camera) {
        Log.v(TAG, "data=" + dat开发者_如何学编程a.length);
        try
        {
            Log.i(TAG,"connecting to server...");

            soc=new Socket(serverAddr,8210);
            outStream=new ObjectOutputStream(soc.getOutputStream());
            Log.i(TAG,"connected");
            outStream.write(data);
            outStream.flush();
            outStream.close();
        }
        catch(Exception ex)
        {
            Log.e(TAG,"error on stream : " + ex);
        }
    }

I just wanted to know the format of byte[] data and how to convert this to image on server. I am using following java code that runs on a pc:

ServerSocket serverSocket = new ServerSocket(8210); 
while (true) { 
  Socket client = serverSocket.accept();  
  byte [] mybytearray  = new byte [497664];
  InputStream is = client.getInputStream();
  FileOutputStream fos = new FileOutputStream("source-copy.jpg");
  BufferedOutputStream bos = new BufferedOutputStream(fos);
  bytesRead = is.read(mybytearray,0,mybytearray.length);
  bos.write(mybytearray, 0 , 497664);
  bos.flush();
  bos.close();
}

On server, it is creating file but the byte[] needs to be decoded in some image format. Does anyone knows how to do that?

Is there anything else i need here?


Assuming this data is from the Camera Preview, you need to find out what the Preview Format is: Android - Camera.Parameters - getPreviewFormat() which points to the list of possible image formats - Android - ImageFormat. You'll need to send the format to the server-side code.

Once the server side has the format, you can search the web to decode or convert to a suitable format.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜