我正在使用LayerDrawable来合并多个可绘制的。现在,我想将我的LayerDrawable导出到一个文件中。
我试过这样做:
Bitmap b = ((BitmapDrawable)myLayerDrawable).getBitmap();
--> ClassCastException...我能做什么?
发布于 2010-11-05 05:24:20
您是否尝试过将可绘制内容绘制到位图画布?我认为调用顺序应该是这样的:
Bitmap b = Bitmap.createBitmap(int width, int height, Bitmap.Config config);
myLayerDrawable.draw(new Canvas(b));然后,您可以将Bitmap对象写入输出流。
发布于 2017-02-06 01:20:17
感谢在我之前回答过的两位用户(@Kyle P和@Anjum Shrimali)。受到他们答案的启发。这对我的情况很有效:
final int width = myLayerDrawable.getIntrinsicWidth();
final int height = myLayerDrawable.getIntrinsicHeight();
final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
myLayerDrawable.setBounds(0, 0, width, height);
myLayerDrawable.draw(new Canvas(bitmap));发布于 2011-08-04 13:05:33
谢谢你的帮助。但是像我这样的初学者需要一些更具体的代码。我试过了,它对我的工作如下。
Bitmap b = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
layerDrawable.setBounds(0, 0, getWidth(), getHeight());
layerDrawable.draw(new Canvas(b));最终,b(位图)是所需的组合位图。
https://stackoverflow.com/questions/4101480
复制相似问题