将FrameLayout和子元素保存在一个位图中

时间:2016-10-31 13:04:25

标签: android bitmap android-framelayout

我有这个布局,并尝试在一个Bitmap中保存FrameLayout和所有子项。 getDrawingCache不返回Bitmap。我尝试thisthis但无效。

<FrameLayout
        android:id="@+id/flPhoto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/imageOne"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:contentDescription="@null"
            android:src="@drawable/image1"/>

        <ImageView
            android:id="@+id/imageTwo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@null"
            android:src="@drawable/image2"
            android:layout_gravity="bottom|right"
            android:layout_margin="15dp"/>

    </FrameLayout>

    imageOne.buildDrawingCache();
    imageTwo.buildDrawingCache();
    flPhoto.setDrawingCacheEnabled(true);
    flPhoto.buildDrawingCache();

    mergedPhoto = flPhoto.getDrawingCache();

    String pathSavedBitmapFile = MediaStore.Images.Media.insertImage(getContentResolver(), mergedPhoto, "", null);
    flPhoto.destroyDrawingCache();

0 个答案:

没有答案