Example usage for android.graphics Bitmap createScaledBitmap

List of usage examples for android.graphics Bitmap createScaledBitmap

Introduction

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

Prototype

public static Bitmap createScaledBitmap(@NonNull Bitmap src, int dstWidth, int dstHeight, boolean filter) 

Source Link

Document

Creates a new bitmap, scaled from an existing bitmap, when possible.

Usage

From source file:com.fabernovel.alertevoirie.ReportDetailsActivity.java

private void setPictureToImageView(String pictureName, ImageView imageView) {
    Bitmap picture = null;/* w  w w. j ava 2  s  .co m*/

    try {
        InputStream in = openFileInput(pictureName);
        picture = BitmapFactory.decodeStream(in);
        in.close();

        LayerDrawable d = (LayerDrawable) getResources().getDrawable(R.drawable.editable_picture_frame);
        if (picture.getHeight() > picture.getWidth()) {
            Matrix m = new Matrix();
            m.postRotate(-90);
            picture = Bitmap.createBitmap(picture, 0, 0, picture.getWidth(), picture.getHeight(), m, true);
        }
        picture = Bitmap.createScaledBitmap(picture, d.getIntrinsicWidth(), d.getIntrinsicHeight(), true);

        d.setDrawableByLayerId(R.id.picture, new BitmapDrawable(picture));
        imageView.setImageDrawable(d);

        if (!hasPic)
            hasPic = (imageView.getId() == R.id.ImageView_far);

        // WTF ?
        // if (hasPic && (imageView.getId() == R.id.ImageView_far)) {
        // loadZoom();
        // }

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.zyk.launcher.AsyncTaskCallback.java

private boolean beginDraggingWidget(View v) {
    mDraggingWidget = true;/*from www  .  j a v  a2 s.  c  o m*/
    // Get the widget preview as the drag representation
    ImageView image = (ImageView) v.findViewById(R.id.widget_preview);
    PendingAddItemInfo createItemInfo = (PendingAddItemInfo) v.getTag();

    // If the ImageView doesn't have a drawable yet, the widget preview hasn't been loaded and
    // we abort the drag.
    if (image.getDrawable() == null) {
        mDraggingWidget = false;
        return false;
    }

    // Compose the drag image
    Bitmap preview;
    Bitmap outline;
    float scale = 1f;
    Point previewPadding = null;

    if (createItemInfo instanceof PendingAddWidgetInfo) {
        // This can happen in some weird cases involving multi-touch. We can't start dragging
        // the widget if this is null, so we break out.
        if (mCreateWidgetInfo == null) {
            return false;
        }

        PendingAddWidgetInfo createWidgetInfo = mCreateWidgetInfo;
        createItemInfo = createWidgetInfo;
        int spanX = createItemInfo.spanX;
        int spanY = createItemInfo.spanY;
        int[] size = mLauncher.getWorkspace().estimateItemSize(spanX, spanY, createWidgetInfo, true);

        FastBitmapDrawable previewDrawable = (FastBitmapDrawable) image.getDrawable();
        float minScale = 1.25f;
        int maxWidth, maxHeight;
        maxWidth = Math.min((int) (previewDrawable.getIntrinsicWidth() * minScale), size[0]);
        maxHeight = Math.min((int) (previewDrawable.getIntrinsicHeight() * minScale), size[1]);

        int[] previewSizeBeforeScale = new int[1];

        preview = getWidgetPreviewLoader().generateWidgetPreview(createWidgetInfo.info, spanX, spanY, maxWidth,
                maxHeight, null, previewSizeBeforeScale);

        // Compare the size of the drag preview to the preview in the AppsCustomize tray
        int previewWidthInAppsCustomize = Math.min(previewSizeBeforeScale[0],
                getWidgetPreviewLoader().maxWidthForWidgetPreview(spanX));
        scale = previewWidthInAppsCustomize / (float) preview.getWidth();

        // The bitmap in the AppsCustomize tray is always the the same size, so there
        // might be extra pixels around the preview itself - this accounts for that
        if (previewWidthInAppsCustomize < previewDrawable.getIntrinsicWidth()) {
            int padding = (previewDrawable.getIntrinsicWidth() - previewWidthInAppsCustomize) / 2;
            previewPadding = new Point(padding, 0);
        }
    } else {
        PendingAddShortcutInfo createShortcutInfo = (PendingAddShortcutInfo) v.getTag();
        Drawable icon = mIconCache.getFullResIcon(createShortcutInfo.shortcutActivityInfo);
        preview = Utilities.createIconBitmap(icon, mLauncher);
        createItemInfo.spanX = createItemInfo.spanY = 1;
    }

    // Don't clip alpha values for the drag outline if we're using the default widget preview
    boolean clipAlpha = !(createItemInfo instanceof PendingAddWidgetInfo
            && (((PendingAddWidgetInfo) createItemInfo).previewImage == 0));

    // Save the preview for the outline generation, then dim the preview
    outline = Bitmap.createScaledBitmap(preview, preview.getWidth(), preview.getHeight(), false);

    // Start the drag
    mLauncher.lockScreenOrientation();
    mLauncher.getWorkspace().onDragStartedWithItem(createItemInfo, outline, clipAlpha);
    mDragController.startDrag(image, preview, this, createItemInfo, DragController.DRAG_ACTION_COPY,
            previewPadding, scale);
    outline.recycle();
    preview.recycle();
    return true;
}

From source file:com.phonemetra.turbo.launcher.AsyncTaskCallback.java

private boolean beginDraggingWidget(View v) {
    mDraggingWidget = true;/*from  w ww. ja  v  a  2  s . c  o  m*/
    // Get the widget preview as the drag representation
    ImageView image = (ImageView) v.findViewById(R.id.widget_preview);
    PendingAddItemInfo createItemInfo = (PendingAddItemInfo) v.getTag();

    // If the ImageView doesn't have a drawable yet, the widget preview hasn't been loaded and
    // we abort the drag.
    if (image.getDrawable() == null) {
        mDraggingWidget = false;
        return false;
    }

    // Compose the drag image
    Bitmap preview;
    Bitmap outline;
    float scale = 1f;
    Point previewPadding = null;

    if (createItemInfo instanceof PendingAddWidgetInfo) {
        // This can happen in some weird cases involving multi-touch. We can't start dragging
        // the widget if this is null, so we break out.
        if (mCreateWidgetInfo == null) {
            return false;
        }

        PendingAddWidgetInfo createWidgetInfo = mCreateWidgetInfo;
        createItemInfo = createWidgetInfo;
        int spanX = createItemInfo.spanX;
        int spanY = createItemInfo.spanY;
        int[] size = mLauncher.getWorkspace().estimateItemSize(spanX, spanY, createWidgetInfo, true);

        FastBitmapDrawable previewDrawable = (FastBitmapDrawable) image.getDrawable();
        float minScale = 1.25f;
        int maxWidth, maxHeight;
        maxWidth = Math.min((int) (previewDrawable.getIntrinsicWidth() * minScale), size[0]);
        maxHeight = Math.min((int) (previewDrawable.getIntrinsicHeight() * minScale), size[1]);

        int[] previewSizeBeforeScale = new int[1];

        preview = getWidgetPreviewLoader().generateWidgetPreview(createWidgetInfo.componentName,
                createWidgetInfo.previewImage, createWidgetInfo.icon, spanX, spanY, maxWidth, maxHeight, null,
                previewSizeBeforeScale);

        // Compare the size of the drag preview to the preview in the AppsCustomize tray
        int previewWidthInAppsCustomize = Math.min(previewSizeBeforeScale[0],
                getWidgetPreviewLoader().maxWidthForWidgetPreview(spanX));
        scale = previewWidthInAppsCustomize / (float) preview.getWidth();

        // The bitmap in the AppsCustomize tray is always the the same size, so there
        // might be extra pixels around the preview itself - this accounts for that
        if (previewWidthInAppsCustomize < previewDrawable.getIntrinsicWidth()) {
            int padding = (previewDrawable.getIntrinsicWidth() - previewWidthInAppsCustomize) / 2;
            previewPadding = new Point(padding, 0);
        }
    } else {
        PendingAddShortcutInfo createShortcutInfo = (PendingAddShortcutInfo) v.getTag();
        Drawable icon = mIconCache.getFullResIcon(createShortcutInfo.shortcutActivityInfo);
        preview = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(),
                Bitmap.Config.ARGB_8888);

        mCanvas.setBitmap(preview);
        mCanvas.save();
        WidgetPreviewLoader.renderDrawableToBitmap(icon, preview, 0, 0, icon.getIntrinsicWidth(),
                icon.getIntrinsicHeight());
        mCanvas.restore();
        mCanvas.setBitmap(null);
        createItemInfo.spanX = createItemInfo.spanY = 1;
    }

    // Don't clip alpha values for the drag outline if we're using the default widget preview
    boolean clipAlpha = !(createItemInfo instanceof PendingAddWidgetInfo
            && (((PendingAddWidgetInfo) createItemInfo).previewImage == 0));

    // Save the preview for the outline generation, then dim the preview
    outline = Bitmap.createScaledBitmap(preview, preview.getWidth(), preview.getHeight(), false);

    // Start the drag
    mLauncher.lockScreenOrientation();
    mLauncher.getWorkspace().onDragStartedWithItem(createItemInfo, outline, clipAlpha);
    mDragController.startDrag(image, preview, this, createItemInfo, DragController.DRAG_ACTION_COPY,
            previewPadding, scale);
    outline.recycle();
    preview.recycle();
    return true;
}

From source file:com.VVTeam.ManHood.Fragment.HistogramFragment.java

private List<PolarPlotData> plotDataForSelfUserData(SelfUserData _usersData) {
    Bitmap orgBmp = BitmapFactory.decodeResource(getResources(), R.drawable.g_circle_b);
    float width = orgBmp.getWidth() * 50.0f / 100.0f;
    float height = width;

    PolarPlotData base = new PolarPlotData(1,
            Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.b_circle_b),
                    (int) width, (int) height, true),
            _usersData.getBasePoint());/*from   w  ww . j a  v  a2  s .c o m*/

    PolarPlotData mid = new PolarPlotData(3,
            Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.b_circle_m),
                    (int) width, (int) height, true),
            //             BitmapFactory.decodeResource(getResources(), R.drawable.b_circle_m),
            _usersData.getMidPoint());

    PolarPlotData upper = new PolarPlotData(5,
            Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.b_circle_s),
                    (int) width, (int) height, true),
            //             BitmapFactory.decodeResource(getResources(), R.drawable.b_circle_s),
            _usersData.getUpperPoint());

    PolarPlotData tip = new PolarPlotData(7,
            //             BitmapFactory.decodeResource(getResources(), R.drawable.b_circle_smaller),
            Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.b_circle_smaller),
                    (int) width, (int) height, true),
            _usersData.getTipPoint());

    List<PolarPlotData> list = new ArrayList<PolarPlotData>();
    list.add(base);
    list.add(mid);
    list.add(upper);
    list.add(tip);

    return list;
}

From source file:com.android.launcher2.AsyncTaskCallback.java

private boolean beginDraggingWidget(View v) {
    mDraggingWidget = true;/*from   w  w w.j ava2 s.c o  m*/
    // Get the widget preview as the drag representation
    ImageView image = (ImageView) v.findViewById(R.id.widget_preview);
    PendingAddItemInfo createItemInfo = (PendingAddItemInfo) v.getTag();

    // If the ImageView doesn't have a drawable yet, the widget preview hasn't been loaded and
    // we abort the drag.
    if (image.getDrawable() == null) {
        mDraggingWidget = false;
        return false;
    }

    // Compose the drag image
    Bitmap preview;
    Bitmap outline;
    float scale = 1f;
    if (createItemInfo instanceof PendingAddWidgetInfo) {
        // This can happen in some weird cases involving multi-touch. We can't start dragging
        // the widget if this is null, so we break out.
        if (mCreateWidgetInfo == null) {
            return false;
        }

        PendingAddWidgetInfo createWidgetInfo = mCreateWidgetInfo;
        createItemInfo = createWidgetInfo;
        int spanX = createItemInfo.spanX;
        int spanY = createItemInfo.spanY;
        int[] size = mLauncher.getWorkspace().estimateItemSize(spanX, spanY, createWidgetInfo, true);

        FastBitmapDrawable previewDrawable = (FastBitmapDrawable) image.getDrawable();
        float minScale = 1.25f;
        int maxWidth, maxHeight;
        maxWidth = Math.min((int) (previewDrawable.getIntrinsicWidth() * minScale), size[0]);
        maxHeight = Math.min((int) (previewDrawable.getIntrinsicHeight() * minScale), size[1]);
        preview = getWidgetPreview(createWidgetInfo.componentName, createWidgetInfo.previewImage,
                createWidgetInfo.icon, spanX, spanY, maxWidth, maxHeight);

        // Determine the image view drawable scale relative to the preview
        float[] mv = new float[9];
        Matrix m = new Matrix();
        m.setRectToRect(new RectF(0f, 0f, (float) preview.getWidth(), (float) preview.getHeight()),
                new RectF(0f, 0f, (float) previewDrawable.getIntrinsicWidth(),
                        (float) previewDrawable.getIntrinsicHeight()),
                Matrix.ScaleToFit.START);
        m.getValues(mv);
        scale = (float) mv[0];
    } else {
        PendingAddShortcutInfo createShortcutInfo = (PendingAddShortcutInfo) v.getTag();
        Drawable icon = mIconCache.getFullResIcon(createShortcutInfo.shortcutActivityInfo);
        preview = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(),
                Bitmap.Config.ARGB_8888);

        mCanvas.setBitmap(preview);
        mCanvas.save();
        renderDrawableToBitmap(icon, preview, 0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
        mCanvas.restore();
        mCanvas.setBitmap(null);
        createItemInfo.spanX = createItemInfo.spanY = 1;
    }

    // Don't clip alpha values for the drag outline if we're using the default widget preview
    boolean clipAlpha = !(createItemInfo instanceof PendingAddWidgetInfo
            && (((PendingAddWidgetInfo) createItemInfo).previewImage == 0));

    // Save the preview for the outline generation, then dim the preview
    outline = Bitmap.createScaledBitmap(preview, preview.getWidth(), preview.getHeight(), false);

    // Start the drag
    mLauncher.lockScreenOrientation();
    mLauncher.getWorkspace().onDragStartedWithItem(createItemInfo, outline, clipAlpha);
    mDragController.startDrag(image, preview, this, createItemInfo, DragController.DRAG_ACTION_COPY, null,
            scale);
    outline.recycle();
    preview.recycle();
    return true;
}

From source file:layout.FragmentBoardItemList.java

private void getThumbnail(final BoardItem bi) {
    bi.downloadingThumb = true;//from   w  ww .  j  a  v a  2  s . c o m
    ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    boolean usingWifi = (info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_WIFI);

    ContextWrapper cw = new ContextWrapper(getActivity().getApplicationContext());
    File directory = cw.getDir("thumbs", Context.MODE_PRIVATE);
    if (!directory.exists()) {
        directory.mkdir();
    }
    final File mypath;
    if (bi.youtubeLink) {
        mypath = new File(directory, currentBoard.getBoardDir() + "_" + bi.youtubeID);
    } else {
        mypath = new File(directory, currentBoard.getBoardDir() + "_" + bi.getThumb());
    }

    if (mypath.exists()) {
        try {
            Bitmap b = BitmapFactory.decodeStream(new FileInputStream(mypath));
            bi.setThumbBitmap(Bitmap.createScaledBitmap(b, 128, 128, false));
            listViewAdapter.notifyDataSetChanged();
            Log.i("getThumb", bi.getThumb() + " from cache");
            return;
        } catch (Exception e) {
            e.printStackTrace();
            displayError(e.getMessage());
        }
    }
    if (settings.getBoolean("setting_downloadOnlyWithWifi", false) == true && !usingWifi) {
        Log.i("getThumb", "Not using wifi");
        return;
    }
    String imgURL = "http://bienvenidoainternet.org/" + bi.getParentBoard().getBoardDir() + "/thumb/"
            + bi.getThumb();
    if (bi.getThumb().startsWith("http")) {
        imgURL = bi.getThumb();
    }
    Ion.with(getContext()).load(imgURL).setLogging("getThumbnail", Log.INFO).asBitmap()
            .setCallback(new FutureCallback<Bitmap>() {
                @Override
                public void onCompleted(Exception e, Bitmap result) {
                    if (e != null) {
                        displayError(e.getMessage());
                        e.printStackTrace();
                    } else {
                        bi.setThumbBitmap(Bitmap.createScaledBitmap(result, 128, 128, false));
                        listViewAdapter.notifyDataSetChanged();
                        FileOutputStream out;
                        try {
                            out = new FileOutputStream(mypath);
                            result.compress(Bitmap.CompressFormat.PNG, 100, out);
                            if (out != null) {
                                out.close();
                            }
                            Log.v("getThumb", bi.getThumb() + " saved.");
                        } catch (Exception e1) {
                            e1.printStackTrace();
                        }
                    }
                }
            });
}

From source file:org.apache.cordova.camera.CameraLauncher.java

/**
 * Return a scaled bitmap based on the target width and height
 *
 * @param imagePath/*w  ww  .  ja va 2  s. c o  m*/
 * @return
 * @throws IOException 
 */
private Bitmap getScaledBitmap(String imageUrl) throws IOException {
    // If no new width or height were specified return the original bitmap
    if (this.targetWidth <= 0 && this.targetHeight <= 0) {
        InputStream fileStream = null;
        Bitmap image = null;
        try {
            fileStream = FileHelper.getInputStreamFromUriString(imageUrl, cordova);
            image = BitmapFactory.decodeStream(fileStream);
        } finally {
            if (fileStream != null) {
                try {
                    fileStream.close();
                } catch (IOException e) {
                    LOG.d(LOG_TAG, "Exception while closing file input stream.");
                }
            }
        }
        return image;
    }

    // figure out the original width and height of the image
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    InputStream fileStream = null;
    try {
        fileStream = FileHelper.getInputStreamFromUriString(imageUrl, cordova);
        BitmapFactory.decodeStream(fileStream, null, options);
    } finally {
        if (fileStream != null) {
            try {
                fileStream.close();
            } catch (IOException e) {
                LOG.d(LOG_TAG, "Exception while closing file input stream.");
            }
        }
    }

    //CB-2292: WTF? Why is the width null?
    if (options.outWidth == 0 || options.outHeight == 0) {
        return null;
    }

    // determine the correct aspect ratio
    int[] widthHeight = calculateAspectRatio(options.outWidth, options.outHeight);

    // Load in the smallest bitmap possible that is closest to the size we want
    options.inJustDecodeBounds = false;
    options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, this.targetWidth,
            this.targetHeight);
    Bitmap unscaledBitmap = null;
    try {
        fileStream = FileHelper.getInputStreamFromUriString(imageUrl, cordova);
        unscaledBitmap = BitmapFactory.decodeStream(fileStream, null, options);
    } finally {
        if (fileStream != null) {
            try {
                fileStream.close();
            } catch (IOException e) {
                LOG.d(LOG_TAG, "Exception while closing file input stream.");
            }
        }
    }
    if (unscaledBitmap == null) {
        return null;
    }

    return Bitmap.createScaledBitmap(unscaledBitmap, widthHeight[0], widthHeight[1], true);
}

From source file:com.remobile.camera.CameraLauncher.java

/**
 * Return a scaled bitmap based on the target width and height
 *
 * @param imageUrl// w w w.j a  v a 2 s .c  o m
 * @return
 * @throws IOException
 */
private Bitmap getScaledBitmap(String imageUrl) throws IOException {
    // If no new width or height were specified return the original bitmap
    if (this.targetWidth <= 0 && this.targetHeight <= 0) {
        InputStream fileStream = null;
        Bitmap image = null;
        try {
            fileStream = FileHelper.getInputStreamFromUriString(imageUrl, cordova);
            image = BitmapFactory.decodeStream(fileStream);
        } finally {
            if (fileStream != null) {
                try {
                    fileStream.close();
                } catch (IOException e) {
                    FLog.d(LOG_TAG, "Exception while closing file input stream.");
                }
            }
        }
        return image;
    }

    // figure out the original width and height of the image
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    InputStream fileStream = null;
    try {
        fileStream = FileHelper.getInputStreamFromUriString(imageUrl, cordova);
        BitmapFactory.decodeStream(fileStream, null, options);
    } finally {
        if (fileStream != null) {
            try {
                fileStream.close();
            } catch (IOException e) {
                FLog.d(LOG_TAG, "Exception while closing file input stream.");
            }
        }
    }

    //CB-2292: WTF? Why is the width null?
    if (options.outWidth == 0 || options.outHeight == 0) {
        return null;
    }

    // determine the correct aspect ratio
    int[] widthHeight = calculateAspectRatio(options.outWidth, options.outHeight);

    // Load in the smallest bitmap possible that is closest to the size we want
    options.inJustDecodeBounds = false;
    options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, this.targetWidth,
            this.targetHeight);
    Bitmap unscaledBitmap = null;
    try {
        fileStream = FileHelper.getInputStreamFromUriString(imageUrl, cordova);
        unscaledBitmap = BitmapFactory.decodeStream(fileStream, null, options);
    } finally {
        if (fileStream != null) {
            try {
                fileStream.close();
            } catch (IOException e) {
                FLog.d(LOG_TAG, "Exception while closing file input stream.");
            }
        }
    }
    if (unscaledBitmap == null) {
        return null;
    }

    return Bitmap.createScaledBitmap(unscaledBitmap, widthHeight[0], widthHeight[1], true);
}

From source file:edu.mum.ml.group7.guessasketch.android.EasyPaint.java

public void setBackgroundUri(Uri uri) {
    if (uri == null) {
        return;// w w  w .ja  v a2s. c o  m
    }

    try {
        //I don't like loading both full-sized and reduced-size copies of the image (the larger copy can use a lot of memory), but I couldn't find any other way to do this.
        Bitmap fullsize = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);
        Bitmap resized = Bitmap.createScaledBitmap(fullsize, contentView.mBitmap.getWidth(),
                contentView.mBitmap.getHeight(), true);
        contentView.mBitmapBackground = resized;
        //contentView.mCanvas = new Canvas( contentView.mBitmapBackground );
    } catch (IOException exception) {
        //TODO: How should we handle this exception?
    }
}

From source file:com.netcompss.ffmpeg4android_client.BaseWizard.java

public String createVideoThumbnail(String fDescriptor) {
    Bitmap thumb = null;//from   ww  w  . j  a v  a  2 s  . c  o m
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
        retriever.setDataSource(fDescriptor);
        thumb = retriever.getFrameAtTime(-1);
        int width = thumb.getWidth();
        int height = thumb.getHeight();
        int max = Math.max(width, height);
        if (max > 512) {
            float scale = 512f / max;
            int w = Math.round(scale * width);
            int h = Math.round(scale * height);
            thumb = Bitmap.createScaledBitmap(thumb, w, h, true);
        }

        FileOutputStream fos = null;
        String extr = Environment.getExternalStorageDirectory().toString();
        File mFolder = new File(extr + "/CHURCH");
        if (!mFolder.exists()) {
            mFolder.mkdir();
        } else {
            mFolder.delete();
            mFolder.mkdir();
        }

        String s = "churchthumbs.png";

        video_thumbpath = new File(mFolder.getAbsolutePath(), s);
        returnPath = video_thumbpath.getAbsolutePath();

        try {
            fos = new FileOutputStream(video_thumbpath);
            thumb.compress(Bitmap.CompressFormat.PNG, 100, fos);
            fos.flush();
            fos.close();
        } catch (FileNotFoundException e) {

            e.printStackTrace();
        } catch (Exception e) {

            e.printStackTrace();
        }

    } catch (IllegalArgumentException ex) {
        // Assume this is a corrupt video file
        Log.e("e", "Failed to create video thumbnail for file description: " + fDescriptor.toString());
    } catch (RuntimeException ex) {
        // Assume this is a corrupt video file.
        Log.e("e", "Failed to create video thumbnail for file description: " + fDescriptor.toString());
    } finally {
        try {
            retriever.release();
        } catch (RuntimeException ex) {
            // Ignore failures while cleaning up.
        }
    }
    return returnPath;
}