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) 

Source Link

Document

Creates a centered bitmap of the desired size.

Usage

From source file:Main.java

public static Bitmap changeBitmap(Bitmap bitmap, int w, int h) {
    Bitmap localBitmap = ThumbnailUtils.extractThumbnail(bitmap, w, h);
    bitmap.recycle();/*  w ww  .  j a va  2 s . co  m*/
    return localBitmap;
}

From source file:Main.java

public static Bitmap getSamllBitmap(Bitmap bitmap, int width, int height) {
    return ThumbnailUtils.extractThumbnail(bitmap, width, height);
}

From source file:Main.java

public static Bitmap getThumb(Bitmap source, int width, int height) {
    return ThumbnailUtils.extractThumbnail(source, width, height);
}

From source file:Main.java

public static Bitmap extractBitmap(Bitmap source, int width, int height) {
    if (!checkBitmap(source)) {
        return null;
    }// w  w  w.  j a v  a2 s. com
    return ThumbnailUtils.extractThumbnail(source, width, height);
}

From source file:Main.java

public static Bitmap getThumbnailsBitmap(Bitmap bitmap, int height, int width) {
    if (bitmap == null) {
        throw new IllegalArgumentException("Bitmap is null, please check you param");
    }/*  w  ww .  ja v  a  2s.  co m*/
    return ThumbnailUtils.extractThumbnail(bitmap, width, height);
}

From source file:Main.java

public static Bitmap getMediaFrame(String filePath) {
    if (TextUtils.isEmpty(filePath)) {
        return null;
    }/*from w w w  .j  a  v  a2  s  . co  m*/
    Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Images.Thumbnails.MINI_KIND);

    bitmap = ThumbnailUtils.extractThumbnail(bitmap, 720, 387);
    return bitmap;
}

From source file:Main.java

public static Bitmap getCroppedBitmap(Bitmap bmp, int radius, int border, int color) {
    Bitmap scaledBitmap;/*  w  w w  .j a va  2s.  c o  m*/
    if (bmp.getWidth() != radius || bmp.getHeight() != radius) {
        scaledBitmap = ThumbnailUtils.extractThumbnail(bmp, radius - 2, radius - 2);
    } else {
        scaledBitmap = bmp;
    }

    Bitmap output = Bitmap.createBitmap(scaledBitmap.getWidth(), scaledBitmap.getHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawCircle(scaledBitmap.getWidth() / 2, scaledBitmap.getHeight() / 2, scaledBitmap.getWidth() / 2,
            paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    final Rect rect = new Rect(0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight());
    canvas.drawBitmap(scaledBitmap, rect, rect, paint);

    if (border > 0) {
        paint.setStrokeWidth(border);
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawCircle(scaledBitmap.getWidth() / 2, scaledBitmap.getHeight() / 2,
                scaledBitmap.getWidth() / 2, paint);
    }

    return output;
}

From source file:Main.java

public static Bitmap getThumbnail(Bitmap bitmap, int width, int height) {
    return ThumbnailUtils.extractThumbnail(bitmap, width, height);
}

From source file:Main.java

public static Bitmap getCircularBitmap(Bitmap bm) {
    int size = 192;

    Bitmap bitmap = ThumbnailUtils.extractThumbnail(bm, size, size);

    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(output);

    final int color = 0xffff0000;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);

    paint.setAntiAlias(true);// ww w .j a  v a2s.c o  m
    paint.setDither(true);
    paint.setFilterBitmap(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawOval(rectF, paint);

    paint.setColor(Color.BLUE);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth((float) 4);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}

From source file:Main.java

public static Bitmap convertToBlackWhite(Bitmap bmp) {
    int width = bmp.getWidth();
    int height = bmp.getHeight();
    int[] pixels = new int[width * height];

    bmp.getPixels(pixels, 0, width, 0, 0, width, height);
    int alpha = 0xFF << 24;
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            int grey = pixels[width * i + j];

            int red = ((grey & 0x00FF0000) >> 16);
            int green = ((grey & 0x0000FF00) >> 8);
            int blue = (grey & 0x000000FF);

            grey = (int) (red * 0.3 + green * 0.59 + blue * 0.11);
            grey = alpha | (grey << 16) | (grey << 8) | grey;
            pixels[width * i + j] = grey;
        }/*from w w  w  . j  a va  2s  .c  o  m*/
    }
    Bitmap newBmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
    newBmp.setPixels(pixels, 0, width, 0, 0, width, height);
    return ThumbnailUtils.extractThumbnail(newBmp, 380, 460);
}