手机截屏和图片分享

1.手机截屏的方法很多,这里我分享一种可以不仅仅截屏当前显示的,还可以把未显示的截取出来!

a.布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical">

    <ScrollView
        android:id="@+id/mScrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <include
                android:id="@+id/title_layout"
                layout="@layout/title_layout"
                android:layout_width="match_parent"
                android:layout_height="@dimen/title_height"
                />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/selected_color"
                android:paddingBottom="10dp"
                >

                <ImageView
                    android:id="@+id/evaluation_time_icon"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_marginLeft="10dp"
                    android:src="@drawable/evaluation_time"/>

                <TextView
                    android:id="@+id/evaluation_time_tv"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignBottom="@+id/evaluation_time_icon"
                    android:layout_marginLeft="5dp"
                    android:layout_toRightOf="@+id/evaluation_time_icon"
                    android:text="用时 00:35:20"
                    android:textColor="@color/whitesmoke"/>


                <com.ustcsoft.yzyx.zxjy.view.CircleProgressView
                    android:id="@+id/evaluation_score_percent"
                    android:layout_width="150dp"
                    android:layout_height="150dp"
                    android:layout_below="@+id/evaluation_time_tv"
                    android:layout_centerHorizontal="true"
                    android:layout_marginBottom="15dp"
                    android:layout_marginTop="15dp"/>


            </RelativeLayout>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginTop="10dp"
                android:background="@color/lineColor"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="34dp"
                android:layout_marginStart="15dp"
                android:gravity="center_vertical"
                android:text="基础分析"
                android:textColor="@color/text_light_black"
                android:textSize="@dimen/txt_size_24px"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/lineColor"/>

            <com.ustcsoft.yzyx.zxjy.view.HorizontalChartView
                android:id="@+id/score_checklist"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/lineColor"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:layout_marginStart="15dp"
                android:gravity="center_vertical"
                android:text="综合评价"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/lineColor"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginEnd="15dp"
                android:layout_marginStart="15dp"
                android:text="此处写专家点评此处写专家点评此处写专此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评此处写专家点评家点评此处写专家点评"
                android:textColor="@color/text_light_black"
                android:textSize="@dimen/txt_size_24px"/>
        </LinearLayout>
    </ScrollView>


</LinearLayout>

2.代码截取

public static Bitmap shotScrollView(ScrollView scrollView) {
    int h = 0;
    Bitmap bitmap = null;
    for (int i = 0; i < scrollView.getChildCount(); i++) {
        h += scrollView.getChildAt(i).getHeight();
        scrollView.getChildAt(i).setBackgroundColor(Color.parseColor("#ffffff"));
    }
    bitmap = Bitmap.createBitmap(scrollView.getWidth(), h, Bitmap.Config.RGB_565);
    final Canvas canvas = new Canvas(bitmap);
    scrollView.draw(canvas);
    return bitmap;
}
原理大家看下,就是画布覆盖。

2.分享图片

    public void shareImage(Bitmap bitmap) {
        try {
            Uri uriToImage = Uri.parse(MediaStore.Images.Media.insertImage(
                mContext.getContentResolver(), bitmap, null, null));
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
            shareIntent.setType("image/*");
            // 遍历所有支持发送图片的应用。找到需要的应用
            startActivity(Intent.createChooser(shareIntent, "分享测评报告"));
        } catch (Exception e) {
//            ContextUtil.getInstance().showToastMsg("分享图片到**失败");
        }
    }
就到这里,亲测可以,前辈的分享,在这里分享给大家。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值