Android ScrollVIew屏幕截图大小太小
我有一个滚动视图,其中包含文本和一些图像。我需要截图和大家分享。我已经成功地拍摄了截图,但图像尺寸太小,无法阅读文本。需要一个高分辨率的屏幕截图 屏幕截图代码:Android ScrollVIew屏幕截图大小太小,android,android-scrollview,Android,Android Scrollview,我有一个滚动视图,其中包含文本和一些图像。我需要截图和大家分享。我已经成功地拍摄了截图,但图像尺寸太小,无法阅读文本。需要一个高分辨率的屏幕截图 屏幕截图代码: private void shareImageUri(Uri uri){ Intent intent = new Intent(android.content.Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_STREAM, uri); i
private void shareImageUri(Uri uri){
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setType("image/png");
startActivity(intent);
}
private void shareBitmapFromView(View view, int height, int width) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Drawable bgDrawable = view.getBackground();
if (bgDrawable != null)
bgDrawable.draw(canvas);
else
canvas.drawColor(Color.WHITE);
view.draw(canvas);
String bitmapPath = MediaStore.Images.Media.insertImage(getContentResolver(), bitmap,"title", null);
Uri bitmapUri = Uri.parse(bitmapPath);
shareImageUri(bitmapUri);
}
articleScrollView = findViewById(R.id.articleScrollView);
shareBitmapFromView(articleScrollView, articleScrollView.getChildAt(0).getHeight(), articleScrollView.getChildAt(0).getWidth());
我就是这样调用这个方法的:
private void shareImageUri(Uri uri){
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setType("image/png");
startActivity(intent);
}
private void shareBitmapFromView(View view, int height, int width) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Drawable bgDrawable = view.getBackground();
if (bgDrawable != null)
bgDrawable.draw(canvas);
else
canvas.drawColor(Color.WHITE);
view.draw(canvas);
String bitmapPath = MediaStore.Images.Media.insertImage(getContentResolver(), bitmap,"title", null);
Uri bitmapUri = Uri.parse(bitmapPath);
shareImageUri(bitmapUri);
}
articleScrollView = findViewById(R.id.articleScrollView);
shareBitmapFromView(articleScrollView, articleScrollView.getChildAt(0).getHeight(), articleScrollView.getChildAt(0).getWidth());
布局文件(如果需要):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activities.ArticleActivity">
<RelativeLayout
android:id="@+id/topBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary">
<ImageButton
android:id="@+id/backButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="@null"
card_view:srcCompat="@drawable/outline_arrow_back_ios_24" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_centerInParent="true"
android:layout_margin="20dp"
android:scaleType="centerInside"
android:src="@drawable/x01" />
</RelativeLayout>
<FrameLayout
android:id="@+id/video_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/topBar"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintLeft_toLeftOf="parent"
card_view:layout_constraintRight_toRightOf="parent"
card_view:layout_constraintTop_toTopOf="parent">
<!--<VideoView-->
<!--android:id="@+id/video_view"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content" />-->
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/video_container"
android:layout_above="@+id/shareButton"
android:background="@android:color/white"
android:orientation="vertical">
<com.mukti.Utlis.BanglaTextView
android:id="@+id/videoTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:text="ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার"
android:textColor="@android:color/black"
android:textSize="@dimen/title_size" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/video_container"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp">
<TextView
android:id="@+id/durationTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:padding="10dp"
android:background="@color/colorPrimary"
android:textColor="@android:color/black"
android:textSize="@dimen/font_size_paragraph" />
<Button
android:id="@+id/downloadButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@color/colorAccent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Download"
android:textColor="@android:color/white" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/articleContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/video_container">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:id="@+id/articleScrollView"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
card_view:cardCornerRadius="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/sc"
android:layout_gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/iconView"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_centerVertical="true"
android:scaleType="centerCrop"
android:src="@drawable/article" />
<com.mukti.Utlis.BanglaTextView
android:id="@+id/titleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার"
android:textColor="@android:color/black"
android:textSize="@dimen/title_size"
android:textStyle="bold" />
<LinearLayout
android:layout_width="100dp"
android:layout_height="5dp"
android:layout_marginLeft="10dp"
android:background="@color/colorAccent"></LinearLayout>
<com.mukti.Utlis.BanglaTextView
android:id="@+id/descriptionView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার but"
android:textSize="@dimen/font_size_paragraph" />
</LinearLayout>
</android.support.v7.widget.CardView>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_below="@+id/topBar"
android:background="@drawable/shadow" />
<Button
android:id="@+id/shareButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorAccent"
android:textColor="@android:color/white"
android:layout_alignParentBottom="true"
android:text="@string/app_name"/>
</RelativeLayout>
在第行之后,可绘制bgdawable=view.getBackground()
send logbgdravable.getIntrinsicHeight()
bgdravable.getIntrinsicWidth()
和canvas.getHeight()
canvas.getWidth()
我根据图像大小得出以下结论:
width: 92px;
height: 1280px;
您需要正确计算bgDrawable的大小 我想你做不到。这是一个操作系统的东西。它会自动压缩拍摄的屏幕截图。问题是,由于您使用的是articleScrollView.getChildAt(0.getWidth()
,因此图像的大小将与视图的大小相同。另外,它不是一个屏幕截图,您正在保存视图的位图
,屏幕截图是当您保存整个屏幕的位图
时。您是否尝试过使用drawingcache进行此操作?是的,它不会占用整个滚动视图。只是看得见的部分@VladyslavMatviienkodid您获取scrollview的绘图缓存,或者它的第一个子项?在第行中显示大小位图如果(bgDrawable!=null)
和第行中的字符串位图路径=…
和第行中的字符串位图路径=…