Example usage for android.graphics Bitmap setHasMipMap

List of usage examples for android.graphics Bitmap setHasMipMap

Introduction

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

Prototype

public final void setHasMipMap(boolean hasMipMap) 

Source Link

Document

Set a hint for the renderer responsible for drawing this bitmap indicating that it should attempt to use mipmaps when this bitmap is drawn scaled down.

Usage

From source file:com.laurencedawson.image_management.ImageManager.java

/**
 * Decode a Bitmap with a given max width and height
 * @param file The Bitmap file//from w w  w.jav a 2s  .com
 * @param reqWidth The requested width of the resulting bitmap
 * @param reqHeight The requested height of the resulting bitmap
 * @return The Bitmap image
 */
@SuppressLint("NewApi")
public static Bitmap decodeBitmap(final File file, final int reqWidth, final int reqHeight) {

    // Serialize all decode on a global lock to reduce concurrent heap usage.
    synchronized (DECODE_LOCK) {

        // Check if the file doesn't exist or has no content
        if (!file.exists() || file.exists() && file.length() == 0) {
            return null;
        }

        // Load a scaled version of the bitmap
        Options opts = null;
        opts = getOptions(file, reqWidth, reqHeight);

        // Set a few additional options for the bitmap opts
        opts.inPurgeable = true;
        opts.inInputShareable = true;
        opts.inDither = true;

        // Grab the bitmap
        Bitmap bitmap = BitmapFactory.decodeFile(file.getPath(), opts);

        // If on JellyBean attempt to draw with mipmaps enabled
        if (bitmap != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            bitmap.setHasMipMap(true);
        }

        // return the decoded bitmap
        return bitmap;
    }
}