1.首先新建路径

 File filedirs = new File(Environment.getExternalStorageDirectory(), "/YuLin/");
if (!filedirs.exists()) {
filedirs.mkdirs();
}

2.生成某个布局的bitmap

    /**
* 生成某个LinearLayout的图片
*/
private Bitmap getLinearLayoutBitmap2(LinearLayout linearLayout, int screenWidth, int screenHeight) {
int w = screenWidth;
int h = screenHeight ;
// 创建对应大小的bitmap
linearLayout.measure(0, 0);
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.WHITE);
linearLayout.draw(canvas);
return bitmap;
}

3.把bitmap保存为文件

 Bitmap btp = getLinearLayoutBitmap2(lin_share, lin_share.getWidth(),
lin_share.getHeight());
File file = new File(filedirs, getTimeStamp() + ".jpg");

4.保存文件到手机

 saveBitmap2(file, btp,99);
/**
* 保存方法
*/
private boolean saveBitmap(File mFile, Bitmap bm) {
if (mFile.exists()) {
mFile.delete();
mFile.mkdirs();
}
try {
FileOutputStream out = new FileOutputStream(mFile);
bm.compress(Bitmap.CompressFormat.JPEG, 40, out);
out.flush();
out.close();
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
} }

注意 不懂得用法 查看下方完整方法

    public File saveSharePic(LinearLayout lin_share) {
File filedirs = new File(Environment.getExternalStorageDirectory(), "/YuLin/");
if (!filedirs.exists()) {
filedirs.mkdirs();
}
Bitmap btp = getLinearLayoutBitmap2(lin_share, lin_share.getWidth(),
lin_share.getHeight());
File file = new File(filedirs, getTimeStamp() + ".jpg");
try {
saveBitmap2(file, btp,99);
} catch (Exception e) {
e.printStackTrace();
}
return file;
}

by:leileitua

将linlayout布局转为bitmap图片和保存的更多相关文章

  1. Android 使用Bitmap将自身保存为文件,BitmapFactory从File中解析图片并防止OOM

    1.使用Bitmap将自身保存为文件 public boolean saveBitmapAsFile(String name, Bitmap bitmap) { File saveFile = new ...

  2. 实现app上对csdn的文章查看,以及文章中图片的保存 (制作csdn app 完结篇)

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/24022165 今天给大家带来CSDN的完结篇,即增加文章的查看和文章中图片的保存 ...

  3. android开发 socket接收图片并保存

    逻辑:接收到socket之后需要将socket发送的图片数据保存下来并通知handler更新界面 关键代码: public void readImage(Socket socket) { try { ...

  4. 【转】前端图片该保存为什么格式?png or jpg?

    疑虑: 图片存储为web格式,该用什么格式保存呢?png?jpg?压缩比例该为多大?css spript的优劣?有时候我们可能会因为一张格式不正确的图片而导致设计品质的下降以及页面性能的降低.了解图片 ...

  5. 如何将Drawable转为Bitmap?

    本文选自StackOverflow(简称:SOF)精选问答汇总系列文章之一,本系列文章将为读者分享国外最优质的精彩问与答,供读者学习和了解国外最新技术.本文将讲解如何将Drawable转为Bitmap ...

  6. Android—将Bitmap图片保存到SD卡目录下或者指定目录

    直接上代码就不废话啦 一:保存到SD卡下 File file = new File(Environment.getExternalStorageDirectory(), System.currentT ...

  7. 上传图片时,使用GDI+中重绘方式将CMYK图片转为RGB图片

    原文:上传图片时,使用GDI+中重绘方式将CMYK图片转为RGB图片 我们知道,如果网站上传图片时,如果用户上传的是CMYK图片,那么在网站上将是无法显示的,通常的现象是出现一个红叉.下面使用将Ima ...

  8. BitMap 图片格式与Base64Image格式互转方法

    BitMap 图片格式与Base64Image格式互转方法 /// <summary> /// 图片转为base64编码的字符串 /// </summary> /// < ...

  9. Android开发之常用必备工具类图片bitmap转成字符串string与String字符串转换为bitmap图片格式

    作者:程序员小冰,CSDN博客:http://blog.csdn.net/qq_21376985 QQ986945193 博客园主页:http://www.cnblogs.com/mcxiaobing ...

随机推荐

  1. day13内置函数

    内置函数 一.三元表达式 def max2(x,y): if x>y: return x else: return y res=max2(10,11) print(res) 三元表达式仅应用于: ...

  2. [BZOJ1187]神奇游乐园(插头DP)

    Description 题意给定一个矩阵,每个格子有权值,在[-1000.1000]内,求一条回路使得回路经过权值和最大,每个格子最多经过一次 2≤n≤100,2≤m≤6 Code #include ...

  3. Intellij Idea 创建JavaWeb项目

    折腾Tomcat折腾了两个晚上,第一个晚上怎么都进不了Tomcat的首页,第二个晚上进去了,但是新建的Web项目,在浏览器中运行,总是 Error on Apache Tomcat: The requ ...

  4. datetime模块详解

    时间运算 >>> datetime.datetime.now() #当前年月 时间datetime.datetime(2018, 2, 13, 16, 12, 6, 850532)& ...

  5. 常用的一些api

    发送手机短信 // 发送短信给安全号码 SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(phon ...

  6. TCP/IP网络编程之套接字类型与协议设置

    套接字与协议 如果相隔很远的两人要进行通话,必须先决定对话方式.如果一方使用电话,另一方也必须使用电话,而不是书信.可以说,电话就是两人对话的协议.协议是对话中使用的通信规则,扩展到计算机领域可整理为 ...

  7. datagrid的增加功能的实现

    一.增加 1.行编辑状态所需的条件 (1)在columns中添加editor,注意type的设置 (2)调用beginEdit方法,开启行编辑 添加到第一行: 添加到最后一行: (2)如果有一行开启了 ...

  8. Flask With

  9. Django Rest Framework threoy

    rest_framework源码分析: 1.as_view() 2.父类的as_view() view = super(APIView, cls).as_view(**initkwargs) 3.vi ...

  10. 【word ladder】cpp

    题目: Given two words (beginWord and endWord), and a dictionary, find the length of shortest transform ...