【发布时间】:2018-07-21 05:30:09
【问题描述】:
我正在制作应用程序的屏幕截图。但我总是得到黑色矩形。
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;
}
}
猜猜,问题在于从 FREContext 获取正确的视图。 尝试了不同的方法来获取相同的结果:
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();
【问题讨论】:
标签: android air adobe screenshot ane