在我的根组件中,我尝试这样截图:
private getImage(v) {
if (topmost().android) {
const view = android.activity.getWindow().getDecorView().getRootView();
view.setDrawingCacheEnabled(true);
const bmp = android.graphics.Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
var source = new imageSource.ImageSource();
view.source.setNativeSource(bmp);
return source;
}
}
但我得到错误,我不能调用getWindow函数在未定义...
JS: ERROR TypeError: Cannot read property 'getWindow' of undefined
有人知道怎么做吗?
发布于 2018-06-14 06:00:04
使用application.android.foregroundActivity
或application.android.context
。这将帮助您获得对当前活动的引用。然后你就可以使用
import * as application from "application";
const view = application.android.foregroundActivity.getWindow().getDecorView().getRootView();
view.setDrawingCacheEnabled(true);
const bmp = android.graphics.Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
如果你需要,这里是游乐场演示链接:https://play.nativescript.org/?template=play-ng&id=cmvjgq
https://stackoverflow.com/questions/50820992
复制相似问题