Example usage for android.graphics Bitmap isMutable

List of usage examples for android.graphics Bitmap isMutable

Introduction

In this page you can find the example usage for android.graphics Bitmap isMutable.

Prototype

public final boolean isMutable() 

Source Link

Document

Returns true if the bitmap is marked as mutable (i.e. can be drawn into)

Usage

From source file:Main.java

/**
 * This method updates the opacity of the bitmap.
 *
 * @param bitmap  The bitmap.//from ww w.j a  v a 2 s.com
 * @param opacity The value of alpha.
 * @return The bitmap after adjusting the opacity.
 */
public static Bitmap adjustOpacity(Bitmap bitmap, int opacity) {

    Bitmap mutableBitmap = bitmap.isMutable() ? bitmap : bitmap.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(mutableBitmap);
    int color = (opacity & 0xFF) << 24;
    canvas.drawColor(color, PorterDuff.Mode.DST_IN);
    return mutableBitmap;
}

From source file:com.crossbow.volley.toolbox.CrossbowImageCache.java

private static boolean bitmapCanBeReused(Bitmap bitmap) {
    return bitmap != null && !bitmap.isRecycled() && bitmap.isMutable();
}

From source file:Main.java

public static Bitmap mergeBitmap(Bitmap oriBmp, Bitmap subBmp, final Rect oriRect, final Rect subRect) {
    if (subBmp == null) {
        return oriBmp;
    }/*from w  w w .  java  2  s  . com*/

    if (oriBmp == null) {
        return null;
    }

    if (!oriBmp.isMutable()) {
        oriBmp = createMutableBitmap(oriBmp);
    }

    Canvas canvas = new Canvas(oriBmp);
    canvas.drawBitmap(subBmp, subRect, oriRect, null);
    return oriBmp;
}

From source file:Main.java

/**
 * Returns reusable bitmap, if exists/*from  w ww . j  av  a 2 s  . c o  m*/
 *
 * @param options Options to look against
 * @return reusable bitmap, if exists
 */
@Nullable
private static Bitmap getBitmapFromReusableSet(@NonNull final BitmapFactory.Options options) {
    Bitmap bitmap = null;

    if (sReusableBitmaps != null && sReusableBitmaps.isEmpty()) {
        synchronized (sReusableBitmaps) {
            final Iterator<SoftReference<Bitmap>> iterator = sReusableBitmaps.iterator();
            Bitmap item;

            while (iterator.hasNext()) {
                item = iterator.next().get();

                if (item != null && item.isMutable()) {
                    // Check to see it the item can be used for inBitmap.
                    if (canUseForInBitmap(item, options)) {
                        bitmap = item;

                        // Remove from reusable set so it can't be used again.
                        iterator.remove();
                        break;
                    }
                } else {
                    // Remove from the set if the reference has been cleared.
                    iterator.remove();
                }
            }
        }
    }
    return bitmap;
}

From source file:com.balieiro.facebook.FriendItem.java

/**
  * The credit of the image processing performed by this method belongs
  * to the author of this site://from  w w  w.java 2s.co  m
  * http://www.piwai.info/transparent-jpegs-done-right/
  * There is an amazing explanation on how to perform this kind of 
  * images transformations.
  */
private static Bitmap getRoundedBitmap(Bitmap source, int pictureMask) {

    BitmapFactory.Options options = new BitmapFactory.Options();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // Starting with Honeycomb, we can load the bitmap as mutable.
        options.inMutable = true;
    }
    // We could also use ARGB_4444, but not RGB_565 (we need an alpha layer).
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    Bitmap bitmap;
    if (source.isMutable()) {
        bitmap = source;
    } else {
        bitmap = source.copy(Bitmap.Config.ARGB_8888, true);
        source.recycle();
    }
    // The bitmap is opaque, we need to enable alpha compositing.
    bitmap.setHasAlpha(true);

    Canvas canvas = new Canvas(bitmap);
    Bitmap mask = BitmapFactory.decodeResource(MyFacebookApp.getContext().getResources(), pictureMask);
    Paint paint = new Paint();
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    canvas.drawBitmap(mask, 0, 0, paint);
    // We do not need the mask bitmap anymore.
    mask.recycle();

    return bitmap;
}

From source file:com.crossbow.volley.toolbox.CrossbowImageCache.java

public Bitmap getBitmapToFill(BitmapFactory.Options options) {
    synchronized (imageCache) {
        for (WeakReference<Bitmap> bitmapSoftReference : unusedBitmaps) {
            if (bitmapSoftReference.get() != null) {
                Bitmap bitmap = bitmapSoftReference.get();
                if (bitmap.isMutable() && canUseForInBitmap(bitmap, options)) {
                    unusedBitmaps.remove(bitmapSoftReference);
                    return bitmap;
                }//ww w .j  av  a2  s . c o m
            }
        }
    }

    return null;
}

From source file:uk.co.senab.bitmapcache.CacheableBitmapDrawable.java

public synchronized boolean isBitmapMutable() {
    Bitmap bitmap = getBitmap();
    return null != bitmap && bitmap.isMutable();
}

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

public Bitmap getBitmapFromReusableSet(BitmapFactory.Options options) {
    //BEGIN_INCLUDE(get_bitmap_from_reusable_set)
    Bitmap bitmap = null;/*w ww . j  a  v  a 2  s  .  c o  m*/
    if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) {
        synchronized (mReusableBitmaps) {
            final Iterator<SoftReference<Bitmap>> iterator = mReusableBitmaps.iterator();
            Bitmap item;

            while (iterator.hasNext()) {
                item = iterator.next().get();

                if (null != item && item.isMutable()) {
                    // Check to see it the item can be used for inBitmap
                    if (canUseForInBitmap(item, options)) {
                        bitmap = item;

                        // Remove from reusable set so it can't be used again
                        iterator.remove();
                        break;
                    }
                } else {
                    // Remove from the set if the reference has been cleared.
                    iterator.remove();
                }
            }
        }
    }
    return bitmap;
    //END_INCLUDE(get_bitmap_from_reusable_set)
}

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

/**
 * @param options - BitmapFactory.Options with out* options populated
 * @return Bitmap that case be used for inBitmap
 *///from  www .  j  a  v  a  2 s .c o m
protected Bitmap getBitmapFromReusableSet(BitmapFactory.Options options) {
    //BEGIN_INCLUDE(get_bitmap_from_reusable_set)
    Bitmap bitmap = null;

    if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) {
        final Iterator<SoftReference<Bitmap>> iterator = mReusableBitmaps.iterator();
        Bitmap item;

        while (iterator.hasNext()) {
            item = iterator.next().get();

            if (null != item && item.isMutable()) {
                // Check to see it the item can be used for inBitmap
                if (canUseForInBitmap(item, options)) {
                    bitmap = item;

                    // Remove from reusable set so it can't be used again
                    iterator.remove();
                    break;
                }
            } else {
                // Remove from the set if the reference has been cleared.
                iterator.remove();
            }
        }
    }

    return bitmap;
    //END_INCLUDE(get_bitmap_from_reusable_set)
}

From source file:gr.unfold.android.tsibato.images.ImageCache.java

protected Bitmap getBitmapFromReusableSet(BitmapFactory.Options options) {
    Bitmap bitmap = null;/* ww  w . j  a  v  a  2s . co  m*/

    if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) {
        final Iterator<SoftReference<Bitmap>> iterator = mReusableBitmaps.iterator();
        Bitmap item;

        while (iterator.hasNext()) {
            item = iterator.next().get();

            if (item != null && item.isMutable()) {
                if (canUseForInBitmap(item, options)) {
                    bitmap = item;

                    iterator.remove();
                    break;
                }
            } else {
                iterator.remove();
            }
        }
    }

    return bitmap;
}