先看看截图效果图

截取scrollview的屏幕
     /**
* 截取scrollview的屏幕
**/
public static Bitmap getScrollViewBitmap(ScrollView scrollView) {
int h = 0;
Bitmap bitmap;
for (int i = 0; i < scrollView.getChildCount(); i++) {
h += scrollView.getChildAt(i).getHeight();
}
// 创建对应大小的bitmap
bitmap = Bitmap.createBitmap(scrollView.getWidth(), h,
Bitmap.Config.RGB_565);
final Canvas canvas = new Canvas(bitmap);
scrollView.draw(canvas);
return bitmap;
}

压缩图片

     /**
* 压缩图片
* @param image
* @return
*/
public static Bitmap compressImage(Bitmap image, int quality) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// 质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中
image.compress(Bitmap.CompressFormat.JPEG, quality, baos);
int options = 100;
// 循环判断如果压缩后图片是否大于100kb,大于继续压缩
// while (baos.toByteArray().length / 1024 > 30) {
// 重置baos
baos.reset();
// 这里压缩options%,把压缩后的数据存放到baos中
image.compress(Bitmap.CompressFormat.JPEG, quality, baos);
// 每次都减少10
// options -= 10;
// }
// 把压缩后的数据baos存放到ByteArrayInputStream中
ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());
// 把ByteArrayInputStream数据生成图片
return BitmapFactory.decodeStream(isBm, null, null);
}

点击按钮弹窗分享dialog提示窗

     //----点分享朋友弹出PopupWindow
private void showPopupWindow() {
View contentView = LayoutInflater.from(GroupBulkActivity.this).inflate(R.layout.popupdow_share, null, false);
window = new PopupWindow(contentView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
window.setOutsideTouchable(true);
window.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
backgroundAlpha(GroupBulkActivity.this, 1.0f);
}
});
backgroundAlpha(GroupBulkActivity.this, 0.5f);//0.0-1.0
iv_wx = contentView.findViewById(R.id.iv_image1);
iv_fiend = contentView.findViewById(R.id.iv_image2);
im_delt = contentView.findViewById(R.id.im_delt);
rl_delt = contentView.findViewById(R.id.rl_delt); window.showAtLocation(LayoutInflater.from(GroupBulkActivity.this).inflate(R.layout.activity_group_bulk, null), Gravity.BOTTOM, 0, 0); iv_wx.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
wechatShare(0);
window.dismiss();
backgroundAlpha(GroupBulkActivity.this, 1f);
}
});
iv_fiend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
wechatShare(1);
window.dismiss();
backgroundAlpha(GroupBulkActivity.this, 1f);
}
});
rl_delt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
window.dismiss();
backgroundAlpha(GroupBulkActivity.this, 1f);
}
});
}

dailog布局

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent"> <LinearLayout
android:id="@+id/ll_share"
android:layout_width="match_parent"
android:layout_height="183dp"
android:background="#FFFFFF"
android:orientation="vertical"> <TextView
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#e4e4e4"/> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="45dp"> <TextView
android:id="@+id/item_popupwindows_Photo"
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="@drawable/bt_nobgd"
android:gravity="center"
android:text="分享给好友"
android:textColor="#585858"
android:textSize="14sp"/> <RelativeLayout
android:id="@+id/rl_delt"
android:layout_width="wrap_content"
android:layout_marginLeft="320dp"
android:layout_height="55dp">
<ImageView
android:id="@+id/im_delt"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_alignParentRight="true"
android:layout_marginRight="21dp"
android:layout_marginTop="14dp"
android:gravity="center"
android:src="@drawable/down"
android:textColor="#585858"
android:textSize="12sp"/>
</RelativeLayout> </RelativeLayout> <TextView
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#9e8888"/> <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
> <LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"> <ImageView
android:id="@+id/iv_image1"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/weixin"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#333333"
android:textSize="13sp"
android:layout_marginTop="5dp"
android:text="微信"/> </LinearLayout> <LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"> <ImageView android:id="@+id/iv_image2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="40dp"
android:src="@drawable/pengyou"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#333333"
android:textSize="13sp"
android:layout_marginTop="5dp"
android:text="朋友圈"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>

分享图片到微信或盆友圈

     private void wechatShare(int flag) {
String baseUrl = Cache.exist(CacheKey.BASE_URL) ? Cache.get(CacheKey.BASE_URL).toString() : URL.BASE_URL;
// 分享图片
Bitmap mBitmap = getScrollViewBitmap(scrollView);
// Bitmap mBitmap = CodeUtils.createImage(data.getCodeUrl(), 200, 200, BitmapFactory.decodeResource(getResources(), R.drawable.logo));
//初始化WXImageObject和WXMediaMessage对象
WXImageObject imageObject = new WXImageObject(compressImage(mBitmap, 80));
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = imageObject;
// mBitmap = getScrollViewBitmap(scrollView);
msg.setThumbImage(Bitmap.createScaledBitmap(mBitmap, 200, 200, true)); mBitmap.recycle();
//构造一个Req
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = String.valueOf(System.currentTimeMillis());
req.message = msg;
req.scene = flag == 0 ? SendMessageToWX.Req.WXSceneSession : SendMessageToWX.Req.WXSceneTimeline;
MyApp.api.sendReq(req); }

最终实现效果如图所示........

 

Android使用scrollview截取整个的屏幕并分享微信的更多相关文章

  1. Android 对ScrollView滚动监听,实现美团、大众点评的购买悬浮效果

    转帖请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming),请尊重他人的辛勤劳动成果,谢谢! 随着移动互联网的快速发展,它已经和我们的生活息息相关了,在 ...

  2. ScrollView控件实现屏幕滚动

    滚动视图是指当拥有很多内容,屏幕显示不完全时,需要通过滚动来显示完整的视图 ScrollView的种类: (1)水平滚动视图:HorizontalScrollView (2)垂直滚动视图:Scroll ...

  3. Android 自定义ScrollView ListView 体验各种纵向滑动的需求

      分类: [android 进阶之路]2014-08-31 12:59 6190人阅读 评论(10) 收藏 举报 Android自定义ScrollView纵向拖动     转载请标明出处:http: ...

  4. Android对ScrollView滚动监听,实现美团、大众点评的购买悬浮效果

    转帖请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/17761431),请尊重他人的辛勤劳动成果,谢谢! 我之前写 ...

  5. 从零開始学android&lt;ScrollView滚动视图.十八.&gt;

    因为手机屏幕的高度有限.所以假设面对组件要显示多组信息的时候,ScrollView视图(滚动视图)能够有效的安排这些组件,浏览时能够自己主动的进行滚屏的操作. android.widget.Scrol ...

  6. android 自定义scrollview 仿QQ空间效果 下拉伸缩顶部图片,上拉回弹 上拉滚动顶部title 颜色渐变

    首先要知道  自定义scrollview 仿QQ效果 下拉伸缩放大顶部图片 的原理是监听ontouch事件,在MotionEvent.ACTION_MOVE事件时候,使用不同倍数的系数,重置布局位置[ ...

  7. Android自定义ScrollView分段加载大文本数据到TextView

    以下内容为原创,转载时请注明链接地址:http://www.cnblogs.com/tiantianbyconan/p/3311658.html 这是我现在碰到的一个问题,如果需要在TextView中 ...

  8. Android自定义ScrollView实现一键置顶功能

    效果图如下: (ps:动态图有太大了,上传不了,就给大家口述一下要实现的功能吧) 要实现的功能:当ScrollView向上滑动超过一定距离后,就渐变的出现一个置顶的按钮,当滑动距离小于我们指定的距离时 ...

  9. android 布局如何支持多种不同屏幕尺寸

    android 布局如何支持多种不同屏幕尺寸 --关于dp.layout-xxx.drawable-xxx作用的小结 转载自:http://blog.csdn.net/vincent_blog/art ...

随机推荐

  1. Elasticsearch-6.7.0系列(五)5044端口 logstash安装

    centos7环境 下载logstash wget https://artifacts.elastic.co/downloads/logstash/logstash-6.7.0.tar.gz      ...

  2. 将mnist获得的数据还原成图片形式

    MNIST是一个手写数字数据集,里面所包含的数据元素是类似于一个1×784矩阵和1×10矩阵的结构,那么,如何将这些数据元素转化为更加直观的图像呢?通过以下python代码,可以实现. from PI ...

  3. spring boot profiles 实现多环境下配置切换 docker版

    1,前言 开发环境总需要调试,docker直接部署不需要调试,环境配置不一样,这里的目的只是,在docker文件环境与开发环境使用不同的配置文件,项目结构如下 2,设置项目配置文件 默认配置文件 ap ...

  4. [VS]反编译_DllToC#_REFLECTOR8.5

    反编译_DllToC#_REFLECTOR8.5 的使用方法可以问度娘 下载地址:百度网盘TonyHeVIP

  5. 【吴恩达课后编程作业】第二周作业 - Logistic回归-识别猫的图片

    1.问题描述 有209张图片作为训练集,50张图片作为测试集,图片中有的是猫的图片,有的不是.每张图片的像素大小为64*64 吴恩达并没有把原始的图片提供给我们 而是把这两个图片集转换成两个.h5文件 ...

  6. n2n网络穿透内网

    目录 前言 配置 网络拓扑: 公网服务器的配置 公司电脑的配置 家里笔记本的配置 注意事项 使用n2n网络 n2n的各edge之间传输数据 补充:NAT类型 后记 前言 在家里的时候比较经常需要对公司 ...

  7. Python数据类型的内置函数之list(列表)

    Python数据类型内置函数 - str(字符串) - list(列表) - tuple(元组) - dict(字典) - set(收集) list(列表)的操作 - (append)在列表最后追加指 ...

  8. 使用GSON工具实现json和其他数据格式间转换

    1 package gson; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 import com.google.gson. ...

  9. 软件职位进阶--立Flag

    PS:是我从看过的书籍<软件测试进阶之路>上摘录的 很喜欢:深耕细作一词,可以走管理leader方向,但我更愿意是技术掌握到手后,兼职管理岗位. 庆幸吧,脚踏实地,没有上来就学自动化,所以 ...

  10. vue+axios完美实现前端路由拦截

    一.路由拦截 1.首先在router的index.js里配置一个自定义字段requireAuth,用该字段来判断进入该路由是否需要登录.如果已经登陆则进入该路由,反之则进入登录页面. 如图是路由配置: ...