LibreOffice Module android (master) 1
ImageUtils.java
Go to the documentation of this file.
1package org.libreoffice.canvas;
2
3import android.graphics.Bitmap;
4import android.graphics.Canvas;
5import android.graphics.drawable.Drawable;
6
7class ImageUtils {
8 static Bitmap getBitmapForDrawable(Drawable drawable) {
9 drawable = drawable.mutate();
10
11 int width = !drawable.getBounds().isEmpty() ?
12 drawable.getBounds().width() : drawable.getIntrinsicWidth();
13
14 width = width <= 0 ? 1 : width;
15
16 int height = !drawable.getBounds().isEmpty() ?
17 drawable.getBounds().height() : drawable.getIntrinsicHeight();
18
19 height = height <= 0 ? 1 : height;
20
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);
25
26 return bitmap;
27 }
28}
29/* vim:set shiftwidth=4 softtabstop=4 expandtab: */