Update git submodules
[LibreOffice.git] / android / source / src / java / org / libreoffice / canvas / ImageUtils.java
blobecda9b77c597e6e13fffb09eb126e10a4e8cb635
1 package org.libreoffice.canvas;
3 import android.graphics.Bitmap;
4 import android.graphics.Canvas;
5 import android.graphics.drawable.Drawable;
7 class ImageUtils {
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);
26 return bitmap;
29 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */