blob: ecda9b77c597e6e13fffb09eb126e10a4e8cb635 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
package org.libreoffice.canvas;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
class ImageUtils {
static Bitmap getBitmapForDrawable(Drawable drawable) {
drawable = drawable.mutate();
int width = !drawable.getBounds().isEmpty() ?
drawable.getBounds().width() : drawable.getIntrinsicWidth();
width = width <= 0 ? 1 : width;
int height = !drawable.getBounds().isEmpty() ?
drawable.getBounds().height() : drawable.getIntrinsicHeight();
height = height <= 0 ? 1 : height;
final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|