android Bitmap Drawable bitByte[] 互相转换 Android
程序员文章站
2022-04-08 23:21:44
...
转换Bitmap to Drawable
BitmapDrawable bitmapDrawable = (BitmapDrawable)bitmap;
Drawable drawable = (Drawable)bitmapDrawable;
Bitmap bitmap = new Bitmap (...);
Drawable drawable = new BitmapDrawable(bitmap);
转换Drawable to Bitmap
Drawable d = ImagesList.get(0);
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
转换Bitmap to byte[]
private byte[] Bitmap2Bytes(Bitmap bm){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray();
}
转换byte[] to Bitmap
private Bitmap Bytes2Bimap(byte[] b){
if(b.length!=0){
return BitmapFactory.decodeByteArray(b, 0, b.length);
}else {
return null;
}
}
BitmapDrawable bitmapDrawable = (BitmapDrawable)bitmap;
Drawable drawable = (Drawable)bitmapDrawable;
Bitmap bitmap = new Bitmap (...);
Drawable drawable = new BitmapDrawable(bitmap);
转换Drawable to Bitmap
Drawable d = ImagesList.get(0);
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
转换Bitmap to byte[]
private byte[] Bitmap2Bytes(Bitmap bm){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray();
}
转换byte[] to Bitmap
private Bitmap Bytes2Bimap(byte[] b){
if(b.length!=0){
return BitmapFactory.decodeByteArray(b, 0, b.length);
}else {
return null;
}
}
上一篇: java过滤关键字
推荐阅读
-
Android 将view 转换为Bitmap出现空指针问题解决办法
-
Android Drawable和Bitmap的转换实例详解
-
Android Bitmap和Drawable相互转换的简单代码
-
Android xhdpi图片转换,能任意转换Android Drawable下“ldpi“, “mdpi“, “hdpi“, “xhdpi“,“xxhdpi“, “xxxhdpi“ 各个类型的图片
-
Android 将view 转换为Bitmap出现空指针问题解决办法
-
Android中Bitmap和Drawable
-
Android,View转换bitmap,bitmap转换drawable
-
Android 将本地资源图片转换成Drawable,进行设置大小操作
-
Android Uri和文件路径互相转换的实例代码
-
Android 打印之将文字转换成 Bitmap 图片,再转换成Bytes 数组 进行打印