我截取了布局的屏幕截图,但提供的图像与显示运行时 View 不相似。 我使用 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>
我需要屏幕截图后的图像,与显示 View 相同。
我正在使用此代码截取屏幕截图。
private void screenshot(View v){
v.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v.getDrawingCache());
v.setDrawingCacheEnabled(false);
}
我面临的问题..用简单的措辞来说,我需要屏幕截图后带有圆角的图像。
最佳答案
试试这个
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;
}
}
关于java - 屏幕截图与显示 View 不相似,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62452995/