1 package org
.libreoffice
.canvas
;
3 import android
.graphics
.Bitmap
;
4 import android
.graphics
.Canvas
;
5 import android
.graphics
.Color
;
6 import android
.graphics
.drawable
.BitmapDrawable
;
7 import android
.graphics
.drawable
.Drawable
;
9 public class ImageUtils
{
10 public static Bitmap
getBitmapForDrawable(Drawable drawable
) {
11 drawable
= drawable
.mutate();
13 int width
= !drawable
.getBounds().isEmpty() ?
14 drawable
.getBounds().width() : drawable
.getIntrinsicWidth();
16 width
= width
<= 0 ?
1 : width
;
18 int height
= !drawable
.getBounds().isEmpty() ?
19 drawable
.getBounds().height() : drawable
.getIntrinsicHeight();
21 height
= height
<= 0 ?
1 : height
;
23 final Bitmap bitmap
= Bitmap
.createBitmap(width
, height
, Bitmap
.Config
.ARGB_8888
);
24 Canvas canvas
= new Canvas(bitmap
);
25 drawable
.setBounds(0, 0, canvas
.getWidth(), canvas
.getHeight());
26 drawable
.draw(canvas
);
31 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */