手机截屏和图片分享
2017-05-23 09:48
246 查看
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.代码截取
原理大家看下,就是画布覆盖。
2.分享图片
就到这里,亲测可以,前辈的分享,在这里分享给大家。
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("分享图片到**失败"); } }
就到这里,亲测可以,前辈的分享,在这里分享给大家。
相关文章推荐
- android 获取手机图片分享源码
- 微信截屏分享、图片压缩处理!
- 微信分享到好友或者朋友圈的截屏图片
- 获取手机截屏图片 ContentObserver
- 手机活动页图片性能优化分享
- ios 部分截屏/将手机页面某一部分转换为图片/截图
- [Egret]长按截屏分享、分享截屏图片、本地存储
- Android应用“安豆苗”让你用手指滑动图片将图片实时分享到另一部手机
- iOS Android 截屏分享图片,&& iOS自定义图片分享
- 手机分享自定义小标题图片和文字内容
- 安卓手机分享图片
- 手机截屏直接分享&反馈
- Android手机截屏生成gif图片
- Android手机截屏生成gif图片
- 调用手机里其他应用分享链接,图片
- 分享 Android 手机屏幕录制并制作成 GIF 演示图片
- adb命令获取手机截屏图片
- 手机web图片左右滑动动画效果分享
- android 获取手机图片裁剪后分享 2
- 【android】给大家分享个小功能,关于低版本安卓手机拍照找不到图片的问题