我截取了布局的屏幕截图,但给出的图像与显示运行时视图不同。
我使用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>
截图后我需要与显示视图相同的图像。
我正在使用此代码截屏。
private void screenshot(View v){
v.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v.getDrawingCache());
v.setDrawingCacheEnabled(false);
}
我所面临的问题..用简单的措辞,我需要截图后带有圆角的图像。
答案 0 :(得分:0)
尝试
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;
}
}
答案 1 :(得分:0)
创建可绘制资源
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>
并使用与获取屏幕截图相同的功能。