// drawable 轉換為 bitmap: 利用canvas物件來達成。 Bitmap drawableToBitmap(Drawable drawable) { Bitmap.Config c = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565; Bitmap bitmap = Bitmap.createBitmap( drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), c); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(canvas); return bitmap; } Bitmap bitmap = ((BitmapDrawable) iconDrawable).getBitmap(); new BitmapDrawable(Bitmap.createScaledBitmap(bitmap, 128, 128, true)) // bitmap 轉換為 drawable: 利用BitmapDrawable直接轉換。 Drawable bitmapToDrawable(Bitmap bitmap) { Drawable drawable = new BitmapDrawable(bitmap);return drawable; }
* Reference
- Camangi 市集 - 關發商資訊
沒有留言:
張貼留言