Android Bitmap Compress smallPic(String oldPath, String newPath, int size)

Here you can find the source of smallPic(String oldPath, String newPath, int size)

Description

small Pic

Declaration

public static File smallPic(String oldPath, String newPath, int size) 

Method Source Code

//package com.java2s;

import java.io.File;

import java.io.FileOutputStream;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

public class Main {
    public static File smallPic(String oldPath, String newPath, int size) {
        BitmapFactory.Options opts = new BitmapFactory.Options();
        Bitmap resizeBmp;/*ww  w.  ja  v  a  2 s .  com*/
        opts.inSampleSize = size;
        opts.inJustDecodeBounds = false;
        resizeBmp = BitmapFactory.decodeFile(oldPath, opts);
        File pictureFile = new File(newPath);
        try {
            if (pictureFile.exists()) {
                pictureFile.delete();
            }
            pictureFile.createNewFile();
            FileOutputStream fOut = new FileOutputStream(pictureFile);
            resizeBmp.compress(Bitmap.CompressFormat.JPEG, 50, fOut);
            fOut.flush();
            fOut.close();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        if (resizeBmp.isRecycled() == false) {
            resizeBmp.recycle();
            System.gc();
        }
        return pictureFile;
    }
}

Related

  1. bitmap2Stream(Bitmap bitmap, CompressFormat format, int quality)
  2. compressBitmapToFile(Bitmap originalBitmap, String path, int quality)
  3. compressToBytes(Bitmap bitmap)
  4. compressToBytes(Bitmap bitmap, int quality)
  5. flattenBitmap(Bitmap bitmap)
  6. compressWithWidth(Bitmap bitmap, int width)
  7. compressWithWidth(String filePath, int width)
  8. compressBitmap(Bitmap bitmap)
  9. compressToBytes(Bitmap bitmap, int quality)