Bitmap drawableToBitmap(Drawable drawable) { Bitmap.Config mConfig; if(drawable.getOpacity() != PixelFormat.OPAQUE){ mConfig=Bitmap.Config.ARGB_8888; }else{ mConfig=Bitmap.Config.RGB_565; } Bitmap bitmap = Bitmap.createBitmap( drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), mConfig); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(canvas); return bitmap; }
或者你也可以這樣:)
((BitmapDrawable)res.getDrawable(R.drawable.youricon)).getBitmap();
沒有留言:
張貼留言