Example usage for android.graphics.drawable BitmapDrawable getBitmap

List of usage examples for android.graphics.drawable BitmapDrawable getBitmap

Introduction

In this page you can find the example usage for android.graphics.drawable BitmapDrawable getBitmap.

Prototype

public final Bitmap getBitmap() 

Source Link

Document

Returns the bitmap used by this drawable to render.

Usage

From source file:br.ufrgs.ufrgsmapas.views.BuildingClusterRenderer.java

private static BitmapDescriptor scaleDown(Context context, int res) {

    BitmapDrawable bitmapDrawable = (BitmapDrawable) ContextCompat.getDrawable(context, res);
    Bitmap bitmap = bitmapDrawable.getBitmap();
    int iconSizePx = MeasureUtils.convertDpToPixel(ICON_SIZE_DP, context);

    Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, iconSizePx, iconSizePx, true);

    return BitmapDescriptorFactory.fromBitmap(scaledBitmap);
}

From source file:Main.java

public static boolean cacheDrawable(String packageName, int resId, BitmapDrawable drawable) {
    try {//from w  ww.  j a v a 2 s.c om
        File f = new File("/data/data/" + PACKAGE_NAME + "/cache/icons/", packageName + "_" + resId);
        if (f.exists()) {
            f.delete();
        }
        f.createNewFile();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        drawable.getBitmap().compress(CompressFormat.PNG, 0, bos);
        new FileOutputStream(f).write(bos.toByteArray());
        f.setReadable(true, false);
        f.setWritable(true, false);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:com.adkdevelopment.rssreader.utils.Utilities.java

/**
 * Retrieves palette from a drawable and returns colors.
 * @param drawable to get palette from./*  w w  w  . j  av  a2 s . com*/
 * @return int[] with 3 colors.
 */
public static int[] getPalette(BitmapDrawable drawable) {

    int[] colors = new int[] { 0, 0, 0 };
    if (drawable != null) {
        Palette palette = Palette.from(drawable.getBitmap()).generate();

        colors[0] = palette.getLightVibrantColor(0);
        if (colors[0] == 0) {
            colors[0] = palette.getLightMutedColor(0);
        }

        colors[1] = palette.getVibrantColor(0);
        if (colors[1] == 0) {
            colors[1] = palette.getMutedColor(0);
        }

        colors[2] = palette.getDarkVibrantColor(0);
        if (colors[2] == 0) {
            colors[2] = palette.getDarkMutedColor(0);
        }
    }

    return colors;
}

From source file:com.sqkj.engine.image.ImageCache.java

/**
 * Get the size in bytes of a bitmap in a BitmapDrawable. Note that from Android 4.4 (KitKat)
 * onward this returns the allocated memory size of the bitmap which can be larger than the
 * actual bitmap data byte count (in the case it was re-used).
 *
 * @param value//  w w w.ja  v a2 s. c o  m
 * @return size in bytes
 */
public static int getBitmapSize(BitmapDrawable value) {
    Bitmap bitmap = value.getBitmap();

    // From KitKat onward use getAllocationByteCount() as allocated bytes can potentially be
    // larger than bitmap byte count.
    if (SdkUtils.hasKitKat()) {
        return bitmap.getAllocationByteCount();
    }

    if (SdkUtils.hasHoneycombMR1()) {
        return bitmap.getByteCount();
    }

    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}

From source file:com.android.volley.cache.BitmapImageCache.java

/**
 * Get the size in bytes of a bitmap in a BitmapDrawable. Note that from Android 4.4 (KitKat)
 * onward this returns the allocated memory size of the bitmap which can be larger than the
 * actual bitmap data byte count (in the case it was re-used).
 *
 * @param value//from ww  w. ja va  2s  .  c  o  m
 * @return size in bytes
 */
public static int getBitmapSize(BitmapDrawable value) {
    Bitmap bitmap = value.getBitmap();
    return getBitmapSize(bitmap);
}

From source file:jahirfiquitiva.iconshowcase.utilities.utils.Utils.java

public static Bitmap drawableToBitmap(Drawable drawable) {
    Bitmap bitmap;/*  w  w  w. j  a v  a  2  s .c  o  m*/
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        if (bitmapDrawable.getBitmap() != null) {
            return bitmapDrawable.getBitmap();
        }
    }
    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
        bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    } else {
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                Bitmap.Config.ARGB_8888);
    }
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    drawable.draw(canvas);
    return bitmap;
}

From source file:com.seun.gallery.util.ImageCache.java

/**
 * Get the size in bytes of a bitmap in a BitmapDrawable. Note that from Android 4.4 (KitKat)
 * onward this returns the allocated memory size of the bitmap which can be larger than the
 * actual bitmap data byte count (in the case it was re-used).
 *
 * @param value image//from w  w  w  . j av a2s  .c o  m
 * @return size in bytes
 */
public static int getBitmapSize(BitmapDrawable value) {
    Bitmap bitmap = value.getBitmap();

    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}

From source file:net.tjado.passwdsafe.lib.view.GuiUtils.java

/**
 * Show a notification with a custom builder
 *//*  www.ja  v  a 2 s  . c o  m*/
public static void showNotification(NotificationManager notifyMgr, NotificationCompat.Builder builder,
        int bigIcon, int notifyId, String notifyTag, Context ctx) {
    BitmapDrawable b = (BitmapDrawable) getDrawable(ctx.getResources(), bigIcon);
    if (b == null) {
        return;
    }
    builder.setLargeIcon(b.getBitmap());
    notifyMgr.notify(notifyTag, notifyId, builder.build());
}

From source file:com.chanlytech.unicorn.cache.ImageCache.java

/**
 * Get the size in bytes of a bitmap in a BitmapDrawable. Note that from Android 4.4 (KitKat)
 * onward this returns the allocated memory size of the bitmap which can be larger than the
 * actual bitmap data byte count (in the case it was re-used).
 *
 * @param value/*from   ww w  .java2  s  .  c  o m*/
 *
 * @return size in bytes
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
public static int getBitmapSize(BitmapDrawable value) {
    Bitmap bitmap = value.getBitmap();

    // From KitKat onward use getAllocationByteCount() as allocated bytes can potentially be
    // larger than bitmap byte count.
    if (AndroidVersion.hasKitKat()) {
        return bitmap.getAllocationByteCount();
    }

    if (AndroidVersion.hasHoneycombMR1()) {
        return bitmap.getByteCount();
    }

    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}

From source file:com.higgses.griffin.cache.ImageCache.java

/**
 * Get the size in bytes of a bitmap in a BitmapDrawable. Note that from Android 4.4 (KitKat)
 * onward this returns the allocated memory size of the bitmap which can be larger than the
 * actual bitmap data byte count (in the case it was re-used).
 *
 * @param value//from  w w  w . ja v a  2  s  .c  o m
 *
 * @return size in bytes
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
public static int getBitmapSize(BitmapDrawable value) {
    Bitmap bitmap = value.getBitmap();

    // From KitKat onward use getAllocationByteCount() as allocated bytes can potentially be
    // larger than bitmap byte count.
    if (GriUAndroidVersion.hasKitKat()) {
        return bitmap.getAllocationByteCount();
    }

    if (GriUAndroidVersion.hasHoneycombMR1()) {
        return bitmap.getByteCount();
    }

    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}