So, I started to work. The main problem was that I did not send the image with proper compression (either .jpg or .png). I found that if you have a Matlab image that Matlab represents simply as a matrix of pixel values โโregardless of compression, you need to create java BufferedImage in order to properly construct the byte array so that you can decode it on the Android side.
Matlab Side
import java.awt.*; import java.io.*; import java.util.*; import javax.imageio.*; serCam = InitUSBcamera; % initialize USB camera as a serial port type = java.lang.String('jpg'); % translating matlab to java outputStream = ByteArrayOutputStream; % create java output stream im = getsnapshot(serCam); % get an image from the camera im2 = imresize(im, [96,128],'nearest'); % reduce the size im3 = im2java2d(im2); % create java Buffered Image ImageIO.write(im3, type, outputStream); bytes = outputStream.toByteArray(); fwrite(serTablet, bytes, 'int8') % send the image // changed to async
source share