如何将可绘制的图形转换为位图?我想设置一个Drawable作为设备的壁纸,但是所有的壁纸功能都接受Bitmap只有。我不能用WallpaperManager因为我是2.1级的。而且,我的绘图文件是从web下载的,并且不驻留在R.drawable.
3 回答
绝地无双
TA贡献1946条经验 获得超4个赞
public static Bitmap drawableToBitmap (Drawable drawable) { Bitmap bitmap = null; if (drawable instanceof BitmapDrawable) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; if(bitmapDrawable.getBitmap() != null) { return bitmapDrawable.getBitmap(); } } if(drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) { bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel } else { bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap;}
眼眸繁星
TA贡献1873条经验 获得超9个赞
Drawable d = ImagesArrayList.get(0); Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
- 3 回答
- 0 关注
- 485 浏览
添加回答
举报
0/150
提交
取消