Bitmap -- Drawable
1:
BitmapDrawable bd= new BitmapDrawable(bitmap)
Bitmap -- byte[]
1:
private byte[] bitmap2Bytes(Bitmap bitmap) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray();
}
Drawable -- Bitmap
1:
Bitmap bitmap = ((BitmapDrawable) getResources().getDrawable(R.drawable.icon)).getBitmap();
2:
private Bitmap drawable2Bitmap(Drawable drawable) {
Bitmap bitmap = Bitmap.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}
byte[] -- Bitmap
1:
public Bitmap bytes2Bimap(byte[] bytes) {
if (bytes.length != 0) {
return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
} else {
return null;
}
}