1 package org
.libreoffice
.canvas
;
3 import android
.graphics
.Bitmap
;
4 import android
.graphics
.Canvas
;
5 import android
.graphics
.drawable
.Drawable
;
8 static Bitmap
getBitmapForDrawable(Drawable drawable
) {
9 drawable
= drawable
.mutate();
11 int width
= !drawable
.getBounds().isEmpty() ?
12 drawable
.getBounds().width() : drawable
.getIntrinsicWidth();
14 width
= width
<= 0 ?
1 : width
;
16 int height
= !drawable
.getBounds().isEmpty() ?
17 drawable
.getBounds().height() : drawable
.getIntrinsicHeight();
19 height
= height
<= 0 ?
1 : height
;
21 final Bitmap bitmap
= Bitmap
.createBitmap(width
, height
, Bitmap
.Config
.ARGB_8888
);
22 Canvas canvas
= new Canvas(bitmap
);
23 drawable
.setBounds(0, 0, canvas
.getWidth(), canvas
.getHeight());
24 drawable
.draw(canvas
);
29 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */