Снимок экрана не похож на вид дисплея - PullRequest
0 голосов
/ 18 июня 2020

Я делаю снимок экрана с макетом, но получаю изображение, не похожее на отображение во время выполнения. Я использовал библиотеку com.github.chrisbanes.photoview.PhotoView для жестов масштабирования изображения.

<LinearLayout
            android:id="@+id/ContentLinearLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/random"
            android:orientation="horizontal"
            android:weightSum="2">

            <androidx.cardview.widget.CardView
                android:id="@+id/ImageViewLeftCard"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:cardCornerRadius="20dp"
                android:layout_margin="1dp"
                android:layout_weight="1">
            <com.github.chrisbanes.photoview.PhotoView
                android:id="@+id/ImageViewLeft"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/blackcolor"/>
            </androidx.cardview.widget.CardView>

            <androidx.cardview.widget.CardView
                android:id="@+id/ImageViewRightCard"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:cardCornerRadius="20dp"
                android:layout_margin="1dp"
                android:layout_weight="1">
            <com.github.chrisbanes.photoview.PhotoView
                android:id="@+id/ImageViewRight"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/blackcolor" />
            </androidx.cardview.widget.CardView>

</LinearLayout>

enter image description here

Мне нужно изображение за снимком экрана, как и в режиме отображения.

Я делаю снимок экрана с этим кодом.

private void screenshot(View v){
    v.setDrawingCacheEnabled(true);
    Bitmap bitmap = Bitmap.createBitmap(v.getDrawingCache());
    v.setDrawingCacheEnabled(false);
}

Проблема, с которой я столкнулся ... простыми словами, мне нужно изображение с закругленными углами после скриншота.

Ответы [ 2 ]

0 голосов
/ 18 июня 2020

Создайте ресурс для рисования

round_shape. xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <corners android:radius="20dp" />
</shape>

и установите его в качестве фона для com.github.chrisbanes.photoview .PhotoView

<LinearLayout
    android:id="@+id/ContentLinearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/random"
    android:orientation="horizontal"
    android:weightSum="2">

    <androidx.cardview.widget.CardView
        android:id="@+id/ImageViewLeftCard"
        app:cardCornerRadius="20dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="1dp"
        android:layout_weight="1">

        <com.github.chrisbanes.photoview.PhotoView
            android:id="@+id/ImageViewLeft"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/round_shape"
            android:background="@color/blackcolor" />
    </androidx.cardview.widget.CardView>

    <androidx.cardview.widget.CardView
        android:id="@+id/ImageViewRightCard"
        app:cardCornerRadius="20dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="1dp"
        android:layout_weight="1">

        <com.github.chrisbanes.photoview.PhotoView
            android:id="@+id/ImageViewRight"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/round_shape"
            android:background="@color/blackcolor" />
    </androidx.cardview.widget.CardView>

</LinearLayout>

И используйте ту же функцию, которую вы используете для получения снимка экрана.

0 голосов
/ 18 июня 2020

попробуйте это

private Bitmap extractBitmap(ViewGroup iViewGroup) {

int width = iViewGroup.getWidth();
int height = iViewGroup.getWidth();

Bitmap createBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

Canvas canvas = new Canvas(createBitmap);

iViewGroup.draw(canvas);

return createBitmap;

  }
}
...