Bitmap,byte[],Drawable,InputStream相互转化工具类
来源:互联网 发布:禁毒网络知识竞赛 编辑:程序博客网 时间:2024/05/18 02:41
1、将byte[]转换成InputStream
byte[] b;
ByteArrayInputStream bais = new ByteArrayInputStream(b);2、 将InputStream转换成byte[]
(1)
InputStream inStream;
ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
byte[] buff = new byte[100];
int rc = 0;
try {
while ((rc = inStream.read(buff, 0, 100)) > 0) {
swapStream.write(buff, 0, rc);
}
} catch (IOException e) {
e.printStackTrace();
}
byte[] in2b = swapStream.toByteArray();
(2)
InputStream is;
String str = "";
byte[] readByte = new byte[1024];
int readCount = -1;
try {
while ((readCount = is.read(readByte, 0, 1024)) != -1) {
str += new String(readByte).trim();
} catch (Exception e) {
e.printStackTrace();
}
byte[] in2b = str.getBytes();
3、 Bitmap转换成byte[]
Bitmap bm;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] b = baos.toByteArray();
4、 byte[]转换成Bitmap
byte[] b;
if (b.length != 0)Bitmap bm = BitmapFactory.decodeByteArray(b, 0, b.length);
5、Drawable转换成Bitmap
Drawable drawable;
Bitmap bitmap = Bitmap
.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565);
6、 Bitmap转换成Drawable
Bitmap bitmap;
BitmapDrawable bd = new BitmapDrawable(bitmap);
Drawable d = (Drawable) bd;
7、 将Bitmap转换成InputStream
Bitmap bm;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream is = new ByteArrayInputStream(baos.toByteArray());
8、 将InputStream转换成Bitmap
InputStream is;
Bitmap bm = BitmapFactory.decodeStream(is);
9、 Drawable转换成InputStream
Drawable d;
//先把drawable转换成Bitmap
//再把Bitmap 转换成 InputStream
10、 InputStream转换成Drawable
InputStream is;
//先把InputStream 转换成 Bitmap
//再把Bitmap 转换成 Drawable
11、 Drawable转换成byte[]
Drawable d;
//先把Drawable 转换成 Bitmap
//再把Bitmap 转换成 byte[]
12、 byte[]转换成Drawable
byte[] b;
//先把byte[] 转换成 Bitmap
//再把Bitmap 转换成 Drawable
- Android中Bitmap,byte[],Drawable,InputStream相互转化工具类
- Android中Bitmap,byte[],Drawable,InputStream相互转化工具类
- Android中Bitmap,byte[],Drawable,InputStream相互转化工具类
- Android中Bitmap,byte[],Drawable,InputStream相互转化工具类
- Android中Bitmap,byte[],Drawable,InputStream相互转化工具类
- Android中Bitmap,byte[],Drawable,InputStream相互转化工具类
- Android中Bitmap,byte[],Drawable,InputStream相互转化工具类
- Bitmap,byte[],Drawable,InputStream相互转化工具类
- 【Android】图片操作之 —— Bitmap,byte[],Drawable,InputStream相互转化工具类
- 实习入职第十二天:Android中Bitmap,byte[],Drawable,InputStream相互转化工具类
- Android中Bitmap,byte[],Drawable,InputStream相互转化
- Bitmap,byte[],Drawable相互转化
- Bitmap,byte[],Drawable相互转化
- Bitmap,byte[],Drawable相互转化
- Bitmap,byte[],Drawable相互转化
- Android Bitmap Drawable byte[] InputStream 相互转换
- Android中Bitmap byte[] Drawable InputStream 转化
- Android工具类之图片流InputStream->(byte[])->Bitmap/Drawable
- nginx 安装ab小工具方法
- 代码签名探析
- 循环得到一条记录中每个字段里的数据
- Jenkins 安装
- Codeforces 367E
- Bitmap,byte[],Drawable,InputStream相互转化工具类
- spring框架的7个模块
- 显示某个目录下的所有文件和文件夹
- MySQL的存储引擎
- 网页爬虫技术浅析
- Android 随手记:Android开发在一个Activity中关闭另一个Activity
- AndroidManifest之内容相关属性
- 块级元素、内联元素之间的转换,以及高度适应
- NYOJ-115 城市平乱