Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android中裁剪屏幕截图_Android - Fatal编程技术网

如何在Android中裁剪屏幕截图

如何在Android中裁剪屏幕截图,android,Android,我试图在我的应用程序中画线。完成后,我想将屏幕另存为图像。但我不希望按钮出现在图像中。我想裁剪它,然后保存它。我尝试使用此代码在onclicklistener中裁剪位图。但它不起作用。 创建位图(位图,5,5,5,5); 这是我的全部代码: content.setDrawingCacheEnabled(true); content.buildDrawingCache(); Bitmap bitmap = Bitmap.createBitmap(content.getD

我试图在我的应用程序中画线。完成后,我想将屏幕另存为图像。但我不希望按钮出现在图像中。我想裁剪它,然后保存它。我尝试使用此代码在onclicklistener中裁剪位图。但它不起作用。 创建位图(位图,5,5,5,5); 这是我的全部代码:

    content.setDrawingCacheEnabled(true); 
    content.buildDrawingCache(); 
    Bitmap bitmap = Bitmap.createBitmap(content.getDrawingCache()); // Bitmap
    Bitmap.createBitmap(bitmap, 5, 5, 5, 5);
    content.setDrawingCacheEnabled(false);

    File file = new File("/sdcard/SurucuImza.jpg");
    FileOutputStream ostream = null;



    try {
        if (bitmap != null) {
            file.createNewFile();
            ostream = new FileOutputStream(file);
            bitmap.compress(CompressFormat.JPEG, 100, ostream); 
            ostream.flush();
            ostream.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    bitmap.recycle();
    bitmap = null;
    ostream = null;
    content.setDrawingCacheEnabled(false);

}

应将此行的结果指定给变量:

Bitmap.createBitmap(bitmap, 5, 5, 5, 5);

//Ex:
Bitmap croppedBitmap = Bitmap.createBitmap(bitmap, 5, 5, 5, 5);
然后保存
crappedbitmap
,而不是
位图。


还有一件事,你确定你的按钮是5x5像素吗?
createBitmap()
的最后两个参数指定了
宽度
高度
由于Android屏幕的大小和密度可变,我建议您不要使用
内容
,但在XML布局中,您有一个
视图组
,该视图组将是“可打印屏幕”的,并且还有另一个区域(视图组外部)使用按钮

这样,您将不得不执行相同的操作,但使用
视图组
而不是
内容