2

I have an android app and noticed that it is onImageAvailable(ImageReader imagereader) function that takes images from the ImageReader when available and processes them. My aim is to manipulate that Image object so that it would process a png file instead of taking that image from the camera. So, I want to change

    this.imagereader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
                    public final void onImageAvailable(ImageReader imageReader) {
                        Image image = imageReader.acquireLatestImage();
                    }
                }, this.thread1);

to something like


    this.imagereader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
                    public final void onImageAvailable(ImageReader imageReader) {
                        Image image = //png path;
                    }
                }, this.thread1);

Is it possible?

  • I mean you have a disassembled version of it. You can change the code, build a new APK from the changed code, sign it yourself, and use that. Or are you asking for a step by step guide on how to reverse engineer an Android app, which is way beyond scope for an SO question. – Gabe Sechan Sep 24 '21 at 19:20
  • I am asking how to convert png file to android.media.Image object – Parviz Ahmedov Sep 24 '21 at 21:28
  • You don't. Image is an abstract class that defines an interface with metadata about the image. Just create a new subclass of Image and implement all the apis. – Gabe Sechan Sep 24 '21 at 21:36

1 Answers1

1

Image is a system resource backed by hardware buffers and you can't just implement your own variant of it. What you can do however is to create an ImageReader with the desired parameters (you likely want to use the same size and format as the original app expect), take a surface from it and draw your png to that surface. You can use a drawing method that suites best your needs - either call lockCanvas and draw on CPU or use Vulkan / OpenGL / Renderscript (depending on the image format an usage flags some of these methods might not be possible).

Also instead of creating an Image using another ImageReader and injecting it into onImageAvailable, I would consider using the existing ImageReader, but replace the producer of the images - camera in your case - with your own one. So basically you can take surface from the existing ImageReader and instead of passing it into camera session, just draw into it yourself.

esentsov
  • 6,372
  • 21
  • 28