android Bitmap Drawable bitByte[] 互相转换 Android
程序员文章站
2022-04-09 08:01:42
...
转换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;
}
}
上一篇: I/O流
下一篇: php不能开发安卓app吗?
推荐阅读
-
Android Bitmap和Drawable的对比
-
Android Drawable和Bitmap的转换实例详解
-
Android Bitmap和Drawable相互转换的简单代码
-
Android Bitmap和Drawable的对比
-
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