先看看截图效果图

截取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. Javascrip错误类型

    Javascrip一旦发现错误,会自动创建一个Error类型对象. Javascrip中有几种错误类型?六种1.SyntaxError 语法错误2.ReferenceError 引用错误3.TypeE ...

  2. Spring事件通知机制

    在上图中,调用 getApplicationEventMulticaster()方法,该方法返回的ApplicationEventMulticaster类型的对象applicationEventMul ...

  3. spring boot 使用 EnvironmentAware 加载配置文件

    @Configuration public class PropertiesUtils implements EnvironmentAware { private int redisExpireTim ...

  4. Qt之QTreeWidget入门

    QTreeWidget的一些基本操作 1.insertTopLevelItems,insertTopLevelItem用来添加顶层的item QTreeWidget *treeWidget = new ...

  5. asp.net mvc5中使用Swagger 自动生成WebApi文档笔记

    Swagger可以自动生成Api说明文档,并内置在线测试,通过NSwagStudio还可以自动生成Api客户端调用代码,以下为具体实现步骤 1.写一个简单的WebApi并加上注释 public cla ...

  6. spark-rpc是如何实现将netty的Channel隐藏在inbox中的

    class TransportServer bootstrap.childHandler(new ChannelInitializer<SocketChannel>() { @Overri ...

  7. jvisualvm远程连接

    1. 今天用jvisualvm远程连接linux上的jdk,jxm方式没有连接成功,后来发现是tomcat安装目录bin下的catalina.sh文件下的JAVA_OPTS中内容格式不对,要有空格,修 ...

  8. arcgis更改栅格数据范围

    栅格数据范围默认为有效值的外接矩形范围,其行列号也是有效值最大行数减去最小行数,最大列数减去最小列号. 通过使用extract by mask 工具可实现改变栅格数据范围. 使用过程中要修改环境功能中 ...

  9. tomcat安装启动之后localhost:8080页面进不去,提示错误500

    具体的错误展示页面如下: 首先,需要考虑到是不是安装的tomcat版本和自己安装的jdk的版本一致,如果不一致,建议将tomcat换成和jdk一致或者高于jdk版本的tomcat版本.(比如安装的jd ...

  10. LeetCode1-5题

    1.两数之和 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用这个 ...