无意中看到 的一篇文章,保存下来了。
/**
* 截屏
* @param v 视图
* @param filePath 保存路径
*/
private void getScreenHot(View v, String filePath)
{
try
{
Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas();
canvas.setBitmap(bitmap);
v.draw(canvas);
try
{
FileOutputStream fos = new FileOutputStream(filePath);
bitmap.compress(CompressFormat.PNG, 100, fos);
}
catch (FileNotFoundException e)
{
throw new InvalidParameterException();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}直接 使用方法:
getScreenHot((View) getWindow().getDecorView(), "/sdcard/test1.png");
本文介绍了一种在Android应用中实现屏幕截图的方法。通过创建Bitmap并使用Canvas进行绘制,可以将当前视图的内容保存为PNG格式的图片文件。该方法适用于需要保存应用内部画面的场景。

被折叠的 条评论
为什么被折叠?



