0

I am converting a NV21 image to a bitmap and then I display it. However, this is apparently very slow (I don't think I have much more than 1 fps). Do you have suggestions to improve that? This is my code:

byte nv21bytearray[] = frame.getImage();
Resolution size = frame.getSize();
Integer height = size.height;
Integer width = size.width;
YuvImage yuvImage = new YuvImage(nv21bytearray, ImageFormat.NV21, width, height, null);
ByteArrayOutputStream os = new ByteArrayOutputStream();
yuvImage.compressToJpeg(new Rect(0, 0, width, height), 100, os);
byte[] jpegByteArray = os.toByteArray();
bitmap = BitmapFactory.decodeByteArray(jpegByteArray, 0, jpegByteArray.length, options);
runOnUiThread(new Runnable() {
     @Override
     public void run() {
         imageView.setImageBitmap(bitmap);
     }
});

The phone I am using is a Motorola Moto E 4G (2nd generation of Moto E).

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Anton
  • 137
  • 2
  • 14
  • Possible duplicate of [Convert NV21 byte array into bitmap readable format](https://stackoverflow.com/questions/32276522/convert-nv21-byte-array-into-bitmap-readable-format) – greeble31 Oct 23 '18 at 18:02
  • If you look at [this answer](https://stackoverflow.com/a/43550068/6759241) (I believe it's the answer _after_ the answer that describes your current solution) you'll find some code that is reasonably fast. The .jpeg compression/decompression is probably taking way too long. – greeble31 Oct 23 '18 at 18:04
  • thank you, it's working a lot better now. – Anton Oct 23 '18 at 19:39

0 Answers0