I am working on android app which takes frames from the camera and display on surface view, I am using camera callbacks to get raw images and then convert it to byte stream and passes to the server for processing and then server return same frame. But the problem is Image view is very slow in drawing images (bitmaps) 15-20 fps. Is there any other solution using I can draw bitmaps quickly. In current code I am processing the bitmaps on a different thread and using UI thread I am setting bitmaps to image view.
Code in Camera callback is
Camera.Size pSize = camera.getParameters().getPreviewSize();
YuvImage yuv = new YuvImage(data, ImageFormat.NV21,
pSize.width, pSize.height, null);
yuv.compressToJpeg(new Rect(0, 0, pSize.width,
pSize.height), 100, baos);
rawImage = baos.toByteArray();
Bitmap bitmap = BitmapFactory.decodeByteArray(rawImage,
0, rawImage.length);
bitmap = Util.getResizedBitmap(bitmap, frameResolution);
final ByteArrayOutputStream rotatedStream = new ByteArrayOutputStream();
bitmap = Util.RotateBitmap(bitmap, 90);
bitmap.compress(Bitmap.CompressFormat.WEBP, 100, rotatedStream);
baos.close();
rawImage = rotatedStream.toByteArray();
if(isStreamingStart== true) {
beforeTime=(new Date()).getTime();
if(client.isConnected()==false){
client.connect();
}
client.send(rawImage);
rotatedStream.flush();
}
and code which returns bitmap is
decodedString = Base64.decode((String) data, Base64.DEFAULT);
byte[] dataString = ((String)data).getBytes();
String stringDecompressed = compressor.decompressToString(dataString);
byte[] imageAsBytes = stringDecompressed.getBytes();
final Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
final Bitmap mutableBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
final Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
HomeActivity.this.runOnUiThread(new Runnable() {
public void run() {
try {
remoteViewImageView.setImageBitmap(bitmap);
} catch (Exception e) {
e.printStackTrace();
}
}
});