android - 只得到部分屏幕截图

标签 android screenshot partial

我正在做一个丝网打印并将其作为电子邮件附件发送。然而,丝网打印通常有一个空白的底部区域,大约是软键盘的大小。但是,我在屏幕截图前隐藏了键盘,它在屏幕上不可见。

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_mail:
            hideKeyboard();
            View v = getWindow().getDecorView().getRootView();
            v.setDrawingCacheEnabled(true);
            myBitmap = v.getDrawingCache();
            saveBitmap(myBitmap);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

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

public void hideKeyboard() {
    View view = this.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm =(InputMethodManager getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

然后将其作为电子邮件附件发送。知道如何去除屏幕打印中软键盘大小的空白吗?

最佳答案

好的,以下似乎有效。就在行之后:

 View v = getWindow().getDecorView().getRootView();

我补充说:

v.invalidate();

我不能发誓这会解决问题,但在进行此更改后问题没有再次出现。过去,在隐藏键盘和创建位图后,屏幕似乎并不总是被重绘,从而在键盘所在的屏幕上留下一个“空白”点。

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

相关文章:

android - 屏幕底部的全宽对话框 - Android

android - 如何在 Android 中实现 RESTFUL 服务?

javascript - 如何在 Chrome 扩展中使用 javascript 截取某些特定区域的屏幕截图?

javascript - Selenium (Node.js) 截屏速度太慢

r - 如何根据组内的子字符串匹配两个数据框

java - fragment 未显示在 Android 导航组件中

android - 在sqlite3中取得平衡

iphone - 如何截取应用程序的屏幕截图(应用程序内)? (iPhone)

Java : fill circle partially and put percentage number inside it

c# - 使用 JSON.NET 进行部分反序列化,保留一些原始字段