android脚步---将layout和其输出一起保存成图片
public void convertViewToBitmap(View view) {
//View view = getLayoutInflater().inflate(R.layout.test_layout, null);
view.setDrawingCacheEnabled(true);
view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
view.buildDrawingCache();
bitmap = view.getDrawingCache(); Date date = new Date(System.currentTimeMillis()); Storage.writeBitmapFile("/sdcard/DCIM/UUCamera/test"+date.toLocaleString()+".jpeg", bitmap); // Testbt.setVisibility(View.VISIBLE);
view.destroyDrawingCache(); }
输入layout对应的vIEW然后进行操作,保存时应用了date,这样每张图片的保存名不同。
应该要注意的是view.measure和 view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());对layout重新进行计算高度和宽度,所以layout务必要封装好,不然会出现移位
以下面layout为例
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
> <LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/screen"
android:background="@drawable/test_bg"
android:gravity="center_horizontal"
android:orientation="vertical"> <RelativeLayout
android:id="@+id/uupic"
android:layout_width="304dp"
android:layout_height="380dp"
android:layout_marginTop="90dp"
android:background="@drawable/test_photo_bg"
android:gravity="center"
> <ImageView
android:id="@+id/myuupic"
android:layout_width="264dp"
android:layout_height="352dp"/>
</RelativeLayout> <RelativeLayout
android:id="@+id/lovepic"
android:layout_height="116dp"
android:layout_width="match_parent"
> <TextView
android:id="@+id/agetext"
android:layout_width="120dp"
android:layout_height="116dp"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="@dimen/age_text_size"
android:background="@drawable/test_age_bg"/> <ImageView
android:id="@+id/genderpic"
android:layout_width="44dp"
android:layout_height="44dp"
android:layout_toRightOf="@+id/agetext"
android:layout_alignParentBottom="true"
android:layout_marginLeft="-30dp"
android:scaleType="fitEnd"/>
<ImageView
android:id="@+id/testimg"
android:layout_width="222dp"
android:layout_height="86dp"
android:layout_toRightOf="@+id/agetext"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
</LinearLayout>
<!-- share and save layout --> <RelativeLayout
android:id="@+id/testbt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginBottom="20dp"
> <Button
android:id="@+id/save"
android:layout_width="148dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@drawable/testbtstyle"
android:text="保存"
android:textColor="#ff4c6c"
android:textSize="20sp" /> <Button
android:id="@+id/share"
android:layout_width="148dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/testbtstyle"
android:text="分享"
android:textColor="#ff4c6c"
android:textSize="20sp" /> </RelativeLayout> </RelativeLayout>
封装成两部分上边显示,下边隐藏
引用时
mScreenShot = mTestView.findViewById(R.id.screen); public void convertViewToBitmap(View view) {
//View view = getLayoutInflater().inflate(R.layout.test_layout, null);
view.setDrawingCacheEnabled(true);
view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
view.buildDrawingCache();
bitmap = view.getDrawingCache(); Date date = new Date(System.currentTimeMillis()); Storage.writeBitmapFile("/sdcard/DCIM/UUCamera/test"+date.toLocaleString()+".jpeg", bitmap); // FileOutputStream fos = new FileOutputStream("/sdcard/DCIM/UUCamera/test.png");
//将Bitmap对象中的图像数据压缩成png格式的图像数据,并将这些数据保存在test.png文件中
// bitmap.compress(CompressFormat.PNG, 100, fos);
//关闭文件输出流
// Testbt.setVisibility(View.VISIBLE);
view.destroyDrawingCache();
if(!ispicsave()) {
return;
} } case R.id.save:
LogMan.e(TAG,"save..."); if(mScreenShot!=null){
// Testbt.setVisibility(View.INVISIBLE);
convertViewToBitmap(mScreenShot);
}
// Testbt.setVisibility(View.VISIBLE);
break;
android脚步---将layout和其输出一起保存成图片的更多相关文章
- android脚步---设置layout隐藏属性
设置layout的属性,应用到android view的setVisibility 有三个值 visibility VISIBLE, INVISIBLE, GONE. 可见的 不可见的 ...
- 【Android Studio安装部署系列】十六、Android studio在layout目录下新建子目录
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 一般用于分类显示不同模块的layout布局文件. 在res/layout文件夹下创建子目录 res/layout鼠标右键——New— ...
- Android - HelloWorld的Layout内容
Android - HelloWorld的Layout内容 本文地址: http://blog.csdn.net/caroline_wendy 作为最基础的Android程序, HelloWorld的 ...
- Android教程-02 在程序中输出Log
视频教程,建议采用超清模式观看 在Android中一般都用Log输出日志,常见的有5个不同的级别 Log.v() Log.d() Log.i() Log.w() Log.e() 当然很多程序员还比较习 ...
- Android 高清加载巨图方案 拒绝压缩图片
Android 高清加载巨图方案 拒绝压缩图片 转载请标明出处: http://blog.csdn.net/lmj623565791/article/details/49300989: 本文出自:[张 ...
- Android(java)学习笔记182:保存数据到SD卡 (附加:保存数据到内存)
1. 如果我们要想读写数据到SD卡中,首先必须知道SD的路径: File file = new File(Environment.getExternalStorageDirectory()," ...
- Android(java)学习笔记238:多媒体之图片画画板案例
1.首先我们编写布局文件activity_main.xml如下: <RelativeLayout xmlns:android="http://schemas.android.com/a ...
- Android——用户登陆及用户名和密码的保存
Android——用户登陆及用户名和密码的保存 在之前的学习过程中已经将Android学习完了,但是在后面将近一年的时间里都没有进行过Android开发,所以对Android的所有的知识点又有点忘 ...
- Java乔晓松-android中调用系统拍照功能并显示拍照的图片
android中调用系统拍照功能并显示拍照的图片 如果你是拍照完,利用onActivityResult获取data数据,把data数据转换成Bitmap数据,这样获取到的图片,是拍照的照片的缩略图 代 ...
随机推荐
- SQLServer 错误: 15404,无法获取有关 Windows NT 组 用户
因做服务器数据库迁移,造成的一系列问题, 1.重启SQL 代理,操作也不可. 然后又进行操作: SQL---------安全性------登录名 中原来的系统用户名前的计算机名更改为现在所用的计算机名 ...
- cmstop中实例化controller_admin_content类传递$this,其构造方法中接收到的是--名为cmstop的参数--包含cmstop中所有属性
主程序cmstop类,实例化controller_admin_content类(接收请求后拼接的).传递cmstop所有属性过去.controller_admin_content.构造方法中接收到名称 ...
- 矩阵快速幂——将运算推广到矩阵上HDU 1575
/* 本题的思路比较简单,就是将递推公式写出来,然后表达成为一个矩阵的形式 最后通过计算就可以得到一个符合题目要求的矩阵, 然后就是将矩阵上面所有的对角线元素相加 得到的结果即为所求的目标 */ #i ...
- nefu 1116 字符串加密
字符串加密 Problem : 1116 Time Limit : 1000ms Memory Limit : 65536K description 给你一段经过加密的字符串,我们称之为密文,现在请你 ...
- EntityFramework日志记录
首先在应用启动时执行:DbInterception.Add(new LogFormatter()); 然后加入如下类: #region [ EF的数据库执行日志记录 ] public class ...
- 在JavaScript中创建命名空间的几种写法
在JavaScript中全局变量经常会引起命名冲突,甚至有时侯重写变量也不是按照你想像中的顺序来的,可以看看下面的例子: var sayHello = function() { return 'Hel ...
- Entity Framework 学习中级篇4—存储过程(下)
在EF中,各个实体的插入.更新和删除也都通过使用存储过程来完成,以便提高点性能.这个类似于数据集.其步骤是:先定义存储过程,然后在VS的可视化设计器,设置存储过程映射即可. 下面,以为Supplier ...
- Linux SSH使用公钥私钥实现免登陆
公钥和私钥(我是文盲,钥字之前都是读yao,这是多音字这里应该念yue),是成对出现的,一旦任何一个做了更改都会验证失败. 1.免登陆的实现: 使用下例中ssky-keygen和ssh-copy- ...
- replication across two data centers
http://andyhan.net/index.php/sys-adm/item/291-hbase-replication http://shitouer.cn/2013/04/hbase-mul ...
- mysql主从数据库
Mysql主从配置,实现读写分离 大型网站为了软解大量的并发访问,除了在网站实现分布式负载均衡,远远不够.到了数据业务层.数据访问层,如果还是传统的数据结构,或者只是单单靠一台服务器扛,如此多的数据库 ...