-1

I'm sorry that I'm not good at English.

I want to make a real-time image manipulation app.(Binarization, color inverse...etc.)

It needs speed, so I want to manipulate it as byte[], without converting to Image or Bitmap.

The format of image that I got from camera was YUV(NV21), but because I don't know about this format, I convert it to JPEG.

but it also doesn't work as I expected.(I thought it would be one byte per one pixel or three byte per one pixel.)

So,

  1. How can I do such manipulation(binarization, color inverse) as JPEG byte array?
  2. or How can I convert NV21 format byte array to RGB byte array?

and I used the method to convert NV21 to JPEG.

YuvImage yuvimage = new YuvImage(bytes, ImageFormat.NV21, width, height, null);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        yuvimage.compressToJpeg(new Rect(0, 0, width, height), 100, outputStream);

and I got yuv image byte array from onPreviewFrame(Camra.PreviewCallback).

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Unknownpgr
  • 87
  • 10
  • +my device doesn't support RGB format, so i have to convert it. – Unknownpgr Jan 02 '18 at 06:55
  • These links might help you: https://stackoverflow.com/questions/32276522/convert-nv21-byte-array-into-bitmap-readable-format https://stackoverflow.com/questions/12469730/confusion-on-yuv-nv21-conversion-to-rgb – Pooja Bansal Jan 02 '18 at 06:56
  • One question per question, please. Both 1 and 2 here should be separate. In addition, you'd need to define what manipulation() is supposed to do, its too vague right now. Furthermore, it would be unusual to work on JPEG directly- its compressed data. You usually turn it into a bitmap and work on that. And you'd never use JPEG as an intermediate format because its lossy- you'd use PNG if anything. – Gabe Sechan Jan 02 '18 at 07:21
  • I'll keep it in mind. I'm not used to here yet. – Unknownpgr Jan 02 '18 at 07:27
  • @GabeSechan Thank you for your advice. – Unknownpgr Jan 02 '18 at 07:29
  • Your best bet is to work with ColorMatrices. You can do Greyscale conversion, Invert, Sepia (or other colors) toning, Brightness/contrast adjustment, Binarization, .... this kind of "filters". Very quickly. And easily. No need for 3rd party libraries. – Phantômaxx Jan 02 '18 at 08:09

1 Answers1

1

I think you can use setPreviewFormat(int) to set other than the default NV21 format for camera captures.

https://developer.android.com/reference/android/graphics/ImageFormat.html#NV21

zealvault
  • 160
  • 10