安卓图片转换
/**
* 对安卓图片的处理
*/
public class GetPicture {
//drawable转化为二进制图片数据
public static byte[] getPicture(Drawable drawable) {
if(drawable == null) {
return null;
}
BitmapDrawable bd = (BitmapDrawable) drawable;
Bitmap bitmap = bd.getBitmap();
ByteArrayOutputStream os = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
return os.toByteArray();
}
//二进制图片数据转化为drawable
public static Drawable getPicture(byte[] b, Context context) {
if(b!=null){
Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length, null);
Drawable bitmapDrawable = new BitmapDrawable(context.getResources(),bitmap);
return bitmapDrawable;
}
return null;
}
}
浙公网安备 33010602011771号