【问题标题】:Android screenshot of a layout to bitmap位图布局的 Android 屏幕截图
【发布时间】:2017-09-17 14:17:11
【问题描述】:

我正在尝试截取由两个图像视图组成的相对布局的屏幕截图。 imageview 之一可以在触摸时移动。

下面是代码的样子

 <RelativeLayout
 android:id="@+id/imageLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
    android:id="@+id/imgPhoto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
   />

<ImageView
    android:id="@+id/imgBackground"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerInParent="true"
    android:layout_centerVertical="true"
    />
 </RelativeLayout>

以下是我用于创建布局位图的代码。

        imageLayout.setDrawingCacheEnabled(true);
        imageLayout.buildDrawingCache();
        Bitmap mergedImage = imageLayout.getDrawingCache();

代码运行良好,它能够截取两张图像的屏幕截图。但是,当我移动 imgPhoto 时,屏幕截图不会反映更改的位置。它仍然显示原始未移动的 imgPhoto。我该如何解决?谢谢。

【问题讨论】:

    标签: android performance android-layout android-imageview android-bitmap


    【解决方案1】:

    在重试之前尝试禁用绘图缓存:

    imageLayout.setDrawingCacheEnabled(true);
    imageLayout.buildDrawingCache();
    Bitmap mergedImage = imageLayout.getDrawingCache();
    imageLayout.setDrawingCacheEnabled(false);
    

    应该可以的。

    您也可以使用View.destroyDrawingCache()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-12
      相关资源
      最近更新 更多