/**
* Creates a Bitmap object from a Drawable object.
*/
private static Bitmap drawableToBitmap(Drawable dr) {
// Attempt to retrieve any existing Bitmap, if possible
if (dr instanceof BitmapDrawable) {
BitmapDrawable bDr = (BitmapDrawable)dr;
if (bDr.getBitmap() != null) {
return bDr.getBitmap();
}
}
// Create a valid blank Bitmap
final Bitmap bitmap;
if (dr.getIntrinsicWidth() <= 0 || dr.getIntrinsicHeight() <= 0) {
// Single color bitmap will be create of 1x1 pixel
bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
} else {
bitmap = Bitmap.createBitmap(dr.getIntrinsicWidth(),
dr.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
}
// Use our Canvas to draw the Drawable onto the Bitmap
Canvas canvas = new Canvas(bitmap);
dr.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
dr.draw(canvas);
return bitmap;
}
LetterTileProvider.java 文件源码
java
阅读 37
收藏 0
点赞 0
评论 0
项目:chips-input-layout
作者:
评论列表
文章目录