0

I making ane which makes screenshot of application. But I always getting black rectangle.

public class TakeScreenshot implements FREFunction {
    @Override
    public FREObject call(FREContext context, FREObject[] args) {
        try {
            View view = context.getActivity().getWindow().getDecorView().getRootView();
            view.setDrawingCacheEnabled(true);
            Bitmap cachedBitmap = Bitmap.createBitmap(view.getDrawingCache());
            Bitmap bitmap = cachedBitmap.copy(cachedBitmap.getConfig(), false);

            FREBitmapData bmd = (FREBitmapData)args[0];
            bmd.acquire();
            bitmap.copyPixelsToBuffer(bmd.getBits());
            bmd.release();
            bmd.invalidateRect(0,0, bitmap.getWidth(), bitmap.getHeight());
            return bmd;

        } catch (FREWrongThreadException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}

Guess, the problem is in taking correct View from FREContext. Have tried different ways to take View with same result:

View view = context.getActivity().getWindow().getDecorView();
View view = context.getActivity().findViewById(android.R.id.content);
View view = context.getActivity().findViewById(android.R.id.content).getRootView();

2 Answers2

1

Unfortunately you cannot capture SurfaceView renders using this method which is how AIR renders its content.

SurfaceView's will always render as black / empty content using the drawing cache. They contain 2 parts, a placeholder View and the render surface. The drawing cache method only captures the view part which is empty.

On API 21 and higher you can use the MediaProjection class to perform a screencapture using a virtual display.

This is the method we use in our Image ANE that can capture a screenshot:

https://airnativeextensions.com/extension/com.distriqt.Image

Michael
  • 3,776
  • 1
  • 16
  • 27
  • thank you for your answer, MediaProjection works great. Can your com.distriqt.Image ane capture screenshots on iOS which contains StageVideo layer with HLS video playback? I faced with another screenshot-problem :D https://stackoverflow.com/questions/48772263/adobe-air-ane-for-ios-take-screenshot-with-stagevideo-layer – morgenshtern Feb 14 '18 at 14:45
0

I have the same problem. I'm playing a local video but in Adobe Air Android I need to take a screenshot (BITMAPDATA.draw(this);) the video turns black

Hamid Naghipour
  • 3,465
  • 2
  • 26
  • 55
  • Please don't add *"Me too"* as answers. It doesn't actually provide an answer to the question. If you have a different but related question, then [ask](/questions/ask) it (reference this one if it will help provide context). If you're interested in this specific question, you can [upvote](/help/privileges/vote-up) it, leave a [comment](/help/privileges/comment), or start a [bounty](/help/privileges/set-bounties) once you have enough [reputation](/help/whats-reputation). – Daniel Widdis Oct 02 '20 at 05:52