gpt4 book ai didi

android - android中的屏幕截图

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:55:06 25 4
gpt4 key购买 nike

我想开发一个应用程序来截取 android 屏幕的屏幕截图..有人知道怎么做吗..?这类似于 koushik duttas 屏幕截图..但是没有使用 root..并且是否有人拥有正在运行的 koushik dutta 屏幕截图应用程序..?对我不起作用..请告诉我..提前致谢。

最佳答案

假设您点击了一个按钮:

findViewById(R.id.button1).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Bitmap bitmap = takeScreenshot();
saveBitmap(bitmap);
}
});

之后你需要这两个方法:

public Bitmap takeScreenshot() {
View rootView = findViewById(android.R.id.content).getRootView();
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
}

public void saveBitmap(Bitmap bitmap) {
File imagePath = new File(Environment.getExternalStorageDirectory() + "/screenshot.png");
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
bitmap.compress(CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
}

关于android - android中的屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3733988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com