Android开发之常用必备工具类图片bitmap转成字符串string与String字符串转换为bitmap图片格式
来源:互联网 发布:免费商城系统 php 编辑:程序博客网 时间:2024/04/27 16:06
作者:程序员小冰,CSDN博客:http://blog.csdn.net/qq_21376985
QQ986945193 博客园主页:http://www.cnblogs.com/mcxiaobing/
今天给大家提供一个常用的工具类。
Android开发之常用必备工具类图片bitmap转成字符串string与String字符串转换为bitmap图片格式
下面是代码。当然最下面会分享出来源文件。
下面是代码:
import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.util.Base64;import java.io.ByteArrayOutputStream;/** * 微博:http://weibo.com/mcxiaobing * ============================================================================ * Copyright (c) 2015-2016 QQ986945193 All rights reserved. * ---------------------------------------------------------------------------- * 类名:Android开发之常用必备工具类图片bitmap转成字符串string与String字符串转换为bitmap图片格式 * ---------------------------------------------------------------------------- * 功能描述:Android开发之常用必备工具类图片bitmap转成字符串string与String字符串转换为bitmap图片格式 * ---------------------------------------------------------------------------- */public class BitmapAndStringUtils { /** * 图片转成string * * @param bitmap * @return */ public static String convertIconToString(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream();// outputstream bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); byte[] appicon = baos.toByteArray();// 转为byte数组 return Base64.encodeToString(appicon, Base64.DEFAULT); } /** * string转成bitmap * * @param st */ public static Bitmap convertStringToIcon(String st) { // OutputStream out; Bitmap bitmap = null; try { // out = new FileOutputStream("/sdcard/aa.jpg"); byte[] bitmapArray; bitmapArray = Base64.decode(st, Base64.DEFAULT); bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length); // bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); return bitmap; } catch (Exception e) { return null; } }}
工具类源代码下载地址:http://download.csdn.net/detail/qq_21376985/9591698
1 0
- Android开发之常用必备工具类图片bitmap转成字符串string与String字符串转换为bitmap图片格式
- Android开发之常用必备工具类图片bitmap转成字符串string与String字符串转换为bitmap图片格式
- android 图片处理工具类,Bitmap转换String ,Drawable, byte[],保存,优化等。
- Android 图片压缩、Bitmap 与 字符串互相转换
- Android Bitmap与String的相互转换
- Android 上传图片到服务器时将bitmap转换为byte[]最后转换为String
- Android base字符串转化为bitmap格式 再转成ImageView
- Base64位编码与String字符串的相互转换,Base64与Bitmap的相互转换
- android bitmap与base64字符串之间转换
- android bitmap与base64字符串之间转换
- android Bitmap与string互转
- android Bitmap与string互转
- android Bitmap与string互转
- android Bitmap与string互转
- Android Bitmap与String互转
- android Bitmap与string互转
- android Bitmap与string互转
- android-bitmap与string互转
- 主调函数分配内存的两次调用
- 文章标题
- Android动画分类和区别
- html(2)之CSS
- python 安装 Beautiful Soup
- Android开发之常用必备工具类图片bitmap转成字符串string与String字符串转换为bitmap图片格式
- 图解首次使用流光5.0
- 使用Servlet实现增删改查的功能
- HDU 4005 边双联通分量
- Python与MySQL联动实例一两则
- CentOS 安装 apache
- 日期格式化 android.text.format.DateFormat
- Java并发之读者-写者几种实现
- Java final String类的详细用法还有特性说明,自己也在学习.