先看看截图效果图

截取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. 7.6 chcount.c -- 使用逻辑与运算符

    include <stdio.h> #define PERIOD '.' int main(void) { char ch; int charcount = 0; while ((ch = ...

  2. 一、新建springBoot项目

    三种方式新建SpringBoot项目:  官网,  myeclipse,  idea 1.官方网站新建(https://start.spring.io/) 1)打开官网,选择自己需要的springBo ...

  3. Spring AOP使用注解记录用户操作日志

    最后一个方法:核心的日志记录方法 package com.migu.cm.aspect; import com.alibaba.fastjson.JSON; import com.migu.cm.do ...

  4. iptables禁止某个mac地址上网

    iptables -I FORWARD  -m mac --mac-source  60:14:B3:7D:6B:39 -j DROP 上面这条命令测试过是可行,禁止这个mac地址上网,马上禁止马上生 ...

  5. 关于new你应当知道的一切

    new在C++中是一个我们经常用到的运算符.由它所创建的变量会被分配在堆中,并且在程序结束之前应当将分配的内存delete掉,否则就会导致内存泄漏.但是除此之外,你对new有更深入的了解吗?本篇文章将 ...

  6. 【摘】Oracle执行计划不走索引的原因总结

    感谢原博主 http://soft.chinabyte.com/database/364/12471864.shtml 在Oracle数据库操作中,为什么有时一个表的某个字段明明有索引,当观察一些语的 ...

  7. js关闭浏览器

                                    不存在的 告诉策划:不好意思,这个需求实现不了. 旧版本浏览器有些支持window.close()方法,目前主流浏览器都不支持,就算让你 ...

  8. IDEA开发环境配置

    1.JDK 2.Maven 3.Tomcat 当找不到 Artifacts , 可以查看一下: 4.配置 terminal 为 git 终端 5.MySQL 6.文件服务器 7.配置 mybatis

  9. 同一台PC,配置多个同一存储平台下的Git账号【两个码云账号,配置在同一台PC上】

    问题:配置完 SSH Key, 使用[http地址]拉取代码异常.报一些没有权限的问题. 原因:配置多个gitee账号(码云)后.拉取代码时,应使用~.ssh/config中Host地址,而不是码云给 ...

  10. bootstrap的使用集锦

    在使用div样式的时候可以根据页面布局来调整大小 <div class="col-md-8 col-md-offset-3"># col-md-8 div所占的空间大小 ...