11

I have this android application.

It use a SurfaceView, from where I get the Surface through the SurfaceHolder.

It also use ExoPlayer to stream videos. However I have instantiated an ImageReader, getting its Surface and passing to the ExoPlayer.

Now, I am in the ImageReader.OnImageAvailableListener#onImageAvailable and I access the latest Image.

I want to manipulate the Image and send the new data to the "SurfaceView" Surface.

How can I "draw" an android.media.Image to an android.view.Surface ?

Vito De Tullio
  • 2,332
  • 3
  • 33
  • 52
  • There is code floating around for converting an `Image` obtained from a `MediaProjection` (Android 5.0+ screenshot API) into a `Bitmap`, taking stride into account. Those have only one plane, though. I assume that there is a recipe for doing the same sort of thing for a YUV `Image`. – CommonsWare Sep 04 '15 at 22:06
  • Were you able to do this ? – RohitMat Feb 20 '18 at 08:58

2 Answers2

0

The question is not clear to me. The way to get android.media.Image is by the Camera2 API, and there you can provide a surface and the "camera" will draw over it. Please refer to Camera2Video example

Another way to get the Image object is from ImageReader (while decoding video for example). In this case you want to draw the image, but you can not provide a surface to the ImageReader(there is an internal surface that is not displayed). In this case you can draw the Image on a SurfaceView. Assuming this is the case, you need to convert an Image to a Bitmap objects.

You have discussion about how perform this here

Arkady
  • 624
  • 1
  • 8
  • 17
-1

Possible duplicate of: how to draw image on surfaceview android

First get your canvas by using lockCanvas() (see here), second get your image and make it a drawable using:

my_bitmap = Bitmap.createBitmap(
  MediaStore.Images.Media.getBitmap(getContentResolver(), uri),
  0,0,90, 90);
drawable=new BitmapDrawable(my_bitmap); 

After that you can draw the drawable to the locked canvas and use unlockCanvasAndPost (Canvas canvas) to post the updated canvas back to the surfaceview.

Community
  • 1
  • 1
Niki van Stein
  • 10,564
  • 3
  • 29
  • 62