1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| /** * Drawable转化成Bitmap * @param drawable drawable * @return Bitmap */ public static Bitmap drawableToBitmap(Drawable drawable) { int intrinsicWidth = drawable.getIntrinsicWidth(); int intrinsicHeight = drawable.getIntrinsicHeight(); Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565; Bitmap bitmap = Bitmap.createBitmap(intrinsicWidth, intrinsicHeight,config); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, intrinsicWidth, intrinsicHeight); drawable.draw(canvas); return bitmap; }
/** * Bitmap转换成Drawable * @param resources resources * @param bm bm * @return */ public static Drawable bitmapToDrawable(Resources resources, Bitmap bm) { Drawable drawable = new BitmapDrawable(resources, bm); return drawable; }
/** * InputStream转换成Bitmap * @param is InputStream流 * @return */ public static Bitmap bitmapToDrawable(InputStream is) { Bitmap bitmap = BitmapFactory.decodeStream(is); return bitmap; }
|