Java – Send Matlab images to Android tablets

Send Matlab images to Android tablets… here is a solution to the problem.

Send Matlab images to Android tablets

I developed an Android app that connects to a laptop running Matlab via Bluetooth SPP. I was able to easily send strings back and forth, and now I’m interested in sending images from Matlab for display on a tablet (48×64 grayscale is enough). I’m not sure how to package the image and send it to the Matlab serial port. I guess you can’t just use fprintf or fwrite.

That’s what I think the Android side looks like

public void drawImage(byte[] buffer){
    ImageView camView = (ImageView)findViewById(R.id.camView);
    Bitmap myBitmap = BitmapFactory.decodeByteArray(buffer, 0, buffer.length);  
    Log.d(TAG,"decoded image");
    if(myBitmap != null){
    camView.setImageBitmap(myBitmap);
    Log.d(TAG,"Trying to display...");
    }
    else{
        Log.d(TAG, "Bitmap = null");
    }
}// end drawImage

Any suggestions for Android or Matlab would be appreciated. Thanks!

Solution

Do you just want to receive serial data from MATLAB? Why not treat it like any other serial data.

I’ll start by debugging through the Android console app to make sure it transfers properly and that the data is transferred the way you want.

Related Problems and Solutions