Example usage for android.media ThumbnailUtils extractThumbnail

List of usage examples for android.media ThumbnailUtils extractThumbnail

Introduction

In this page you can find the example usage for android.media ThumbnailUtils extractThumbnail.

Prototype

public static Bitmap extractThumbnail(Bitmap source, int width, int height, int options) 

Source Link

Document

Creates a centered bitmap of the desired size.

Usage

From source file:Main.java

public static Bitmap getPictureImage(String urlPath) {
    Bitmap bitmap = null;//from www  .java2 s . com
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    bitmap = BitmapFactory.decodeFile(urlPath, options);
    options.inJustDecodeBounds = false;
    int h = options.outHeight;
    int w = options.outWidth;
    int beWidth = w / 100;
    int beHeight = h / 80;
    int be = 1;
    if (beWidth < beHeight) {
        be = beWidth;
    } else {
        be = beHeight;
    }
    if (be <= 0) {
        be = 1;
    }
    options.inSampleSize = be;
    bitmap = BitmapFactory.decodeFile(urlPath, options);
    bitmap = ThumbnailUtils.extractThumbnail(bitmap, 100, 80, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
    return bitmap;
}

From source file:com.ape.transfer.util.FileIconLoader.java

public static Bitmap getMyImageThumbnail(String filePath, int width, int height) {
    File file = new File(filePath);
    if (!file.exists())
        return null;

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;//from w  w  w.j  a  v  a2 s . co m

    // Decode the width and height of the bitmap, but don't load the bitmap
    // to RAM
    BitmapFactory.decodeFile(file.getPath(), options);

    int max = Math.max(options.outHeight, options.outWidth);

    // Compute the sampleSize of the options
    int size = (int) (max / (float) Math.max(width, height));
    if (size <= 0) {
        size = 1;
    }
    options.inSampleSize = size;

    // Decode the width and height of the bitmap and load the bitmap to RAM
    options.inJustDecodeBounds = false;

    Bitmap iconBitmap = BitmapFactory.decodeFile(file.getPath(), options);

    iconBitmap = ThumbnailUtils.extractThumbnail(iconBitmap, width, height,
            ThumbnailUtils.OPTIONS_RECYCLE_INPUT);

    return iconBitmap;
}

From source file:com.ape.transfer.util.FileIconLoader.java

public static Bitmap getMyVideoThumbnail(String videoPath, int width, int height) {
    File file = new File(videoPath);
    if (!file.exists())
        return null;

    Bitmap bitmap = null;//from   w  w w  .j ava2 s.  c  o  m
    bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, Images.Thumbnails.MICRO_KIND);
    bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
    return bitmap;
}

From source file:org.chromium.chrome.browser.ntp.snippets.SnippetArticleViewHolder.java

private void fadeThumbnailIn(SnippetArticle snippet, Bitmap thumbnail) {
    mImageCallback = null;/*  ww  w  .ja  va 2  s  .  c  o m*/
    if (thumbnail == null)
        return; // Nothing to do, we keep the placeholder.

    // We need to crop and scale the downloaded bitmap, as the ImageView we set it on won't be
    // able to do so when using a TransitionDrawable (as opposed to the straight bitmap).
    // That's a limitation of TransitionDrawable, which doesn't handle layers of varying sizes.
    Resources res = mThumbnailView.getResources();
    int targetSize = res.getDimensionPixelSize(R.dimen.snippets_thumbnail_size);
    Bitmap scaledThumbnail = ThumbnailUtils.extractThumbnail(thumbnail, targetSize, targetSize,
            ThumbnailUtils.OPTIONS_RECYCLE_INPUT);

    // Store the bitmap to skip the download task next time we display this snippet.
    snippet.setThumbnailBitmap(scaledThumbnail);

    // Cross-fade between the placeholder and the thumbnail.
    Drawable[] layers = { mThumbnailView.getDrawable(),
            new BitmapDrawable(mThumbnailView.getResources(), scaledThumbnail) };
    TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
    mThumbnailView.setImageDrawable(transitionDrawable);
    transitionDrawable.startTransition(FADE_IN_ANIMATION_TIME_MS);
}

From source file:com.atwal.wakeup.battery.util.Utilities.java

public static Bitmap getFbBitmap(Drawable drawable, int width, int height) {
    Bitmap bitmap = drawableToBitmap(drawable);
    Bitmap resizeBitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height,
            ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
    return resizeBitmap;
}

From source file:com.ibuildapp.romanblack.FanWallPlugin.FanWallPlugin.java

/**
 * Sets up image after it was taken from camera or chosen from gallery.
 *///  w w  w . j  av  a2s .c  o  m
private void setImage() {
    Bitmap input = Statics.resizeBitmapToMaxSize(imagePath, (int) (IMAGE_ADDED_SIZE * density));
    Bitmap avaBtm = ThumbnailUtils.extractThumbnail(input, (int) (IMAGE_ADDED_SIZE * density),
            (int) (IMAGE_ADDED_SIZE * density), ThumbnailUtils.OPTIONS_RECYCLE_INPUT);

    imageHolder.setVisibility(View.VISIBLE);
    userImage.setImageBitmap(avaBtm);
}