如何采取截图? [英] How to take a screenshots?
本文介绍了如何采取截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开发一个应用程序,它是能够采取截屏,我发现下面的code,让我这样做
I am developing an app which is able to take screen shots and I found the following code which allows me to do that
Toast.makeText(this, formattedDate, Toast.LENGTH_SHORT).show();
Process sh = Runtime.getRuntime().exec("su", null,null);
OutputStream os = sh.getOutputStream();
os.write(("/system/bin/screencap -p " + "/sdcard/img.png").getBytes("ASCII"));
os.flush();
它保存图像与图像的名字我可以在code改变它,但我想要的当前日期和时间作为名称。我想puttinge这样的:
It saves the image with image name I can change it in code but I want the current date and time as the name. I tried puttinge this:
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = df.format(c.getTime());
但把formattedDate在图像的地方它不工作后
But after putting formattedDate at the place of image it does not work
推荐答案
在某些情况下,有一个:字符的文件名是不允许的。你可能希望将其替换为。或 -
in some cases having a ":" character in the filename is not allowed. You might want to replace it with "." or "-".
编辑:
试试这个:
os.write(("/system/bin/screencap -p " + "\"/sdcard/"+formattedDate+".png\"").getBytes("ASCII"));
这篇关于如何采取截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文