0

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();
                                }

                            }
                            });
Sunil Soni
  • 443
  • 3
  • 18
  • Are you sure the bottleneck is drawing bitmaps on a view but not network or compressing/decompressing ? – Tumbus Feb 05 '16 at 05:45
  • Checkout this answer :- http://stackoverflow.com/a/12836811/1384010 – Adarsh Yadav Feb 05 '16 at 05:55
  • yes I checked the network, client and server is connected using websockets on WAN. and also I tried to draw bitmaps on camera callback method. it also slow compare to surface view – Sunil Soni Feb 05 '16 at 06:23

0 Answers0