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:com.royclarkson.springagram.model.ItemResource.java

public void setImage(String imageDataUri) {
    String imageDataString = imageDataUri.substring(imageDataUri.indexOf(",") + 1);
    byte[] imageData = Base64.decode(imageDataString, Base64.DEFAULT);
    Bitmap original = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
    this.image = ThumbnailUtils.extractThumbnail(original, IMAGE_WIDTH, IMAGE_HEIGHT);
    this.thumbnail = ThumbnailUtils.extractThumbnail(original, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
}

From source file:com.dycody.android.idealnote.utils.BitmapHelper.java

/**
 * Retrieves a the bitmap relative to attachment based on mime type
 *//*from   w w  w  . j a  v a 2 s.co m*/
public static Bitmap getBitmapFromAttachment(Context mContext, Attachment mAttachment, int width, int height) {
    Bitmap bmp = null;
    String path;
    mAttachment.getUri().getPath();

    // Video
    if (Constants.MIME_TYPE_VIDEO.equals(mAttachment.getMime_type())) {
        // Tries to retrieve full path from ContentResolver if is a new video
        path = StorageHelper.getRealPathFromURI(mContext, mAttachment.getUri());
        // .. or directly from local directory otherwise
        if (path == null) {
            path = FileHelper.getPath(mContext, mAttachment.getUri());
        }
        bmp = ThumbnailUtils.createVideoThumbnail(path, Thumbnails.MINI_KIND);
        if (bmp == null) {
            return null;
        } else {
            bmp = BitmapUtils.createVideoThumbnail(mContext, bmp, width, height);
        }

        // Image
    } else if (Constants.MIME_TYPE_IMAGE.equals(mAttachment.getMime_type())
            || Constants.MIME_TYPE_SKETCH.equals(mAttachment.getMime_type())) {
        try {
            bmp = BitmapUtils.getThumbnail(mContext, mAttachment.getUri(), width, height);
        } catch (NullPointerException e) {
            bmp = null;
        }

        // Audio
    } else if (Constants.MIME_TYPE_AUDIO.equals(mAttachment.getMime_type())) {
        bmp = ThumbnailUtils
                .extractThumbnail(
                        BitmapUtils.decodeSampledBitmapFromResourceMemOpt(mContext.getResources()
                                .openRawResource(com.dycody.android.idealnote.R.raw.play), width, height),
                        width, height);

        // File
    } else if (Constants.MIME_TYPE_FILES.equals(mAttachment.getMime_type())) {

        // vCard
        if (Constants.MIME_TYPE_CONTACT_EXT.equals(FilenameUtils.getExtension(mAttachment.getName()))) {
            bmp = ThumbnailUtils
                    .extractThumbnail(
                            BitmapUtils.decodeSampledBitmapFromResourceMemOpt(mContext.getResources()
                                    .openRawResource(com.dycody.android.idealnote.R.raw.vcard), width, height),
                            width, height);
        } else {
            bmp = ThumbnailUtils
                    .extractThumbnail(
                            BitmapUtils.decodeSampledBitmapFromResourceMemOpt(mContext.getResources()
                                    .openRawResource(com.dycody.android.idealnote.R.raw.files), width, height),
                            width, height);
        }
    }

    return bmp;
}

From source file:it.feio.android.omninotes.utils.BitmapHelper.java

/**
 * Retrieves a the bitmap relative to attachment based on mime type
 *///  w  w  w  .  java 2 s  .  co  m
public static Bitmap getBitmapFromAttachment(Context mContext, Attachment mAttachment, int width, int height) {
    Bitmap bmp = null;
    String path;
    mAttachment.getUri().getPath();

    // Video
    if (Constants.MIME_TYPE_VIDEO.equals(mAttachment.getMime_type())) {
        // Tries to retrieve full path from ContentResolver if is a new video
        path = StorageHelper.getRealPathFromURI(mContext, mAttachment.getUri());
        // .. or directly from local directory otherwise
        if (path == null) {
            path = FileHelper.getPath(mContext, mAttachment.getUri());
        }
        bmp = ThumbnailUtils.createVideoThumbnail(path, Thumbnails.MINI_KIND);
        if (bmp == null) {
            return null;
        } else {
            bmp = BitmapUtils.createVideoThumbnail(mContext, bmp, width, height);
        }

        // Image
    } else if (Constants.MIME_TYPE_IMAGE.equals(mAttachment.getMime_type())
            || Constants.MIME_TYPE_SKETCH.equals(mAttachment.getMime_type())) {
        try {
            bmp = BitmapUtils.getThumbnail(mContext, mAttachment.getUri(), width, height);
        } catch (NullPointerException e) {
            bmp = null;
        }

        // Audio
    } else if (Constants.MIME_TYPE_AUDIO.equals(mAttachment.getMime_type())) {
        bmp = ThumbnailUtils.extractThumbnail(
                BitmapUtils.decodeSampledBitmapFromResourceMemOpt(
                        mContext.getResources().openRawResource(R.drawable.play), width, height),
                width, height);

        // File
    } else if (Constants.MIME_TYPE_FILES.equals(mAttachment.getMime_type())) {

        // vCard
        if (Constants.MIME_TYPE_CONTACT_EXT.equals(FilenameUtils.getExtension(mAttachment.getName()))) {
            bmp = ThumbnailUtils.extractThumbnail(
                    BitmapUtils.decodeSampledBitmapFromResourceMemOpt(
                            mContext.getResources().openRawResource(R.drawable.vcard), width, height),
                    width, height);
        } else {
            bmp = ThumbnailUtils.extractThumbnail(
                    BitmapUtils.decodeSampledBitmapFromResourceMemOpt(
                            mContext.getResources().openRawResource(R.drawable.files), width, height),
                    width, height);
        }
    }

    return bmp;
}

From source file:com.github.chenxiaolong.dualbootpatcher.switcher.CacheRomThumbnailTask.java

private Bitmap createThumbnailFromUri(Uri uri) {
    try {/* ww  w.  j  a v  a2 s  .  co m*/
        InputStream input = mContext.getContentResolver().openInputStream(uri);
        Bitmap bitmap = BitmapFactory.decodeStream(input);
        input.close();

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

        return ThumbnailUtils.extractThumbnail(bitmap, 500, 500);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:org.appspot.apprtc.util.ThumbnailsCacheManager.java

/**
 * Add thumbnail to cache/*from ww  w.j a va  2  s  . c o m*/
 * @param imageKey: thumb key
 * @param bitmap:   image for extracting thumbnail
 * @param path:     image path
 * @param px:       thumbnail dp
 * @return Bitmap
 */
private static Bitmap addThumbnailToCache(String imageKey, Bitmap bitmap, String path, int px) {

    Bitmap thumbnail = ThumbnailUtils.extractThumbnail(bitmap, px, px);

    // Add thumbnail to cache
    addBitmapToCache(imageKey, thumbnail);

    return thumbnail;
}

From source file:com.aimfire.gallery.service.PhotoProcessor.java

private void saveThumbnail(String sbsPath, String thumbPath) {
    try {/*  w ww .  j  a  v  a  2 s . co m*/
        BitmapRegionDecoder decoder = null;
        Bitmap bmp = null;

        decoder = BitmapRegionDecoder.newInstance(sbsPath, false);
        bmp = decoder.decodeRegion(new Rect(0, 0, decoder.getWidth() / 2, decoder.getHeight()), null);

        Bitmap thumb = ThumbnailUtils.extractThumbnail(bmp, MainConsts.THUMBNAIL_SIZE,
                MainConsts.THUMBNAIL_SIZE);

        FileOutputStream fos;
        fos = new FileOutputStream(thumbPath);
        thumb.compress(CompressFormat.JPEG, 50, fos);
        fos.close();

        if (bmp != null) {
            bmp.recycle();
        }

        if (thumb != null) {
            thumb.recycle();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:sg.fxl.topeka.widget.quiz.ImageQuizView.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_TAKE_PHOTO && resultCode == Activity.RESULT_OK) {
        button.setVisibility(GONE);/*from w w  w  .ja  va  2s . c om*/
        imageView.setVisibility(VISIBLE);

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
        Bitmap bitmap = BitmapFactory.decodeFile(photoFile.getPath(), options);
        imageView.setImageBitmap(ThumbnailUtils.extractThumbnail(bitmap, 500, 500));
        allowAnswer();
    }
}

From source file:com.dldzkj.app.renxing.MainActivity.java

public void getLoginUserData() {
    AppDbUtils util = new AppDbUtils();
    u = util.getLoginUser(SPUtils.getLoginId(this));
    if (u == null)
        return;// w  w w.  j  a  v a 2  s . com
    if (u.getPortrait() != null && !u.getPortrait().isEmpty()) {
        ImageLoader.getInstance().displayImage(WebUtils.RENXING_WEB + u.getPortrait(), nonImg,
                MyApplication.img_option, new ImageLoadingListener() {
                    @Override
                    public void onLoadingStarted(String s, View view) {

                    }

                    @Override
                    public void onLoadingFailed(String s, View view, FailReason failReason) {

                    }

                    @Override
                    public void onLoadingComplete(String s, View view, Bitmap bitmap) {
                        Bitmap resizeBmp = ThumbnailUtils.extractThumbnail(bitmap,
                                BmpUtils.dip2px(getBaseContext(), 36), BmpUtils.dip2px(getBaseContext(), 36));
                        toolbar.setNavigationIcon(new CircleImageDrawable(resizeBmp, false, 0));
                    }

                    @Override
                    public void onLoadingCancelled(String s, View view) {

                    }
                });

    }
}

From source file:ch.epfl.sweng.evento.tabs_fragment.ContentFragment.java

private void displayMosaic() {
    mGridLayout = (GridLayout) mView.findViewById(R.id.gridLayout);
    mGridLayout.setRowCount(mNumberOfRow);
    mGridLayout.setColumnCount(mNumberOfColumn);
    mGridLayout.removeAllViews();//from ww w .j  a  v a 2s. c  o  m
    List<String> mParty = new ArrayList<String>(Arrays.asList("Birthday", "Dinner", "Surprise", "Garden", "Tea",
            "Beer-Pong", "Dance and Ball", "Go for Hang-over"));

    boolean[] tmpBooleanRow = new boolean[mNumberOfColumn];
    Span tmpSpanSmtgOrNot = Span.NOTHING;
    int spanning = 0;
    for (int yPos = 0, countEvent = 0; countEvent < MAX_NUMBER_OF_EVENT
            && countEvent < mNumberOfEvent; yPos++) {
        for (int xPos = 0; xPos < mNumberOfColumn && countEvent < MAX_NUMBER_OF_EVENT
                && countEvent < mNumberOfEvent; xPos++, countEvent++) {
            final MyView tView = new MyView(mView.getContext(), xPos, yPos);
            final int count = countEvent;
            tView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(mActivity, EventActivity.class);
                    intent.putExtra(EventActivity.CURRENT_EVENT_KEY, mEvents.get(count).getID());
                    mActivity.startActivity(intent);
                }
            });
            if (mDisplayOrNot.get(yPos)[xPos]) {
                Point size = new Point();
                mActivity.getWindowManager().getDefaultDisplay().getSize(size);
                mWidthColumn = size.x / 3 - 4 * PADDING;
                if (mEvents.get(countEvent).getTags().contains("Foot!")
                        || CreatingEventActivity.getSport().contains(
                                mEvents.get(countEvent).getTags().toString().replace("]", "").replace("[", ""))
                        || CreatingEventActivity.getStuff().contains(mEvents.get(countEvent).getTags()
                                .toString().replace("]", "").replace("[", ""))) {
                    tmpSpanSmtgOrNot = Span.NOTHING;
                    //tView.setImageResource(R.drawable.football);
                    Bitmap bitmap = mEvents.get(countEvent).getPicture();
                    mHeightRow = size.y / 6 - 4 * PADDING;
                    tView.setImageBitmap(ThumbnailUtils.extractThumbnail(bitmap, mWidthColumn, mHeightRow));
                } else if (mParty.contains(
                        mEvents.get(countEvent).getTags().toString().replace("]", "").replace("[", ""))) {
                    tmpSpanSmtgOrNot = Span.TWO_ROWS;
                    Bitmap bitmap = mEvents.get(countEvent).getPicture();
                    mHeightRow = size.y / 3 - 6 * PADDING;
                    tView.setImageBitmap(ThumbnailUtils.extractThumbnail(bitmap, mWidthColumn, mHeightRow));
                    ++spanning;
                    mDisplayOrNot.get(yPos + 1)[xPos] = false;
                } else {
                    tmpSpanSmtgOrNot = Span.NOTHING;
                    Bitmap bitmap = mEvents.get(countEvent).getPicture();
                    mHeightRow = size.y / 6 - 4 * PADDING;
                    tView.setImageBitmap(ThumbnailUtils.extractThumbnail(bitmap, mWidthColumn, mHeightRow));
                }

                tView.setAdjustViewBounds(false);
                mMyViews.add(tView);

                switch (tmpSpanSmtgOrNot) {
                case NOTHING:
                    while (yPos >= mNumberOfRow) {
                        ++mNumberOfRow;
                        mGridLayout.setRowCount(mNumberOfRow);
                    }
                    addViewToGridLayout(tView, yPos, xPos, 1, 1, mWidthColumn);
                    break;
                case TWO_ROWS:
                    while ((yPos + 1) >= mNumberOfRow) {
                        ++mNumberOfRow;
                        mGridLayout.setRowCount(mNumberOfRow);
                    }
                    addViewToGridLayout(tView, yPos, xPos, 2, 1, mWidthColumn);
                    break;
                case TWO_COLUMNS:
                    addViewToGridLayout(tView, yPos, xPos, 1, 2, mWidthColumn);
                    break;
                }
            } else {
                countEvent--;
            }
        }
    }
}

From source file:com.aimfire.gallery.service.MovieProcessor.java

private void saveThumbnail(Bitmap bitmap, String path) {
    FileOutputStream fos;//from   w  w  w  .  j a  v  a2s  .  c o  m

    Bitmap thumbnail = ThumbnailUtils.extractThumbnail(bitmap, MainConsts.THUMBNAIL_SIZE,
            MainConsts.THUMBNAIL_SIZE);
    try {
        fos = new FileOutputStream(path);
        thumbnail.compress(CompressFormat.JPEG, 100, fos);
        fos.close();
    } catch (Exception e) {
        FirebaseCrash.report(e);
    }
}