Вопрос

I was looking at this class : https://developer.android.com/reference/android/media/ImageReader.html

What I want is to get an InputStream from the ImageReader class and get the image data which is being rendering into the current surface. Current Surface means the currently displaying android screen. I looked at an example inside the AOSP code but it was really tough to understand. Please it would be really helpful if someone provides me with a nice example of ImageReader class.

Это было полезно?

Решение

It sounds like you're trying to use ImageReader to pull data out of an arbitrary Surface. It doesn't work that way.

ImageReader is a buffer queue "CPU consumer", which is a fancy way of saying that when you send data to its Surface, code running on the CPU can examine the data directly. Not all surfaces can be handled this way -- the usage flags are set when the surface is created -- so you need to create the Surface with ImageReader#getSurface() and then pass that to something that wants to send data to a Surface.

As the documentation notes, "Several Android media API classes accept Surface objects as targets to render to, including MediaPlayer, MediaCodec, and RenderScript Allocations."

The primary customer for ImageReader is the camera, demonstrated in the CTS test you linked to. It doesn't really work with MediaCodec decoders yet because the output formats are different from camera (and some of them are proprietary).

The virtual display test is closer to what you want, because you can direct the output of a virtual display to a Surface. For an app with normal privileges you can only send your own app's output there. The Android 4.4 "screenrecord" command does something similar.

(If you want to record what you're drawing on a SurfaceView, and you're rendering with OpenGL, there are some alternatives demonstrated here and here.)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top