Android Zip Unzip Directory compress(String filePath, int width, int height)

Here you can find the source of compress(String filePath, int width, int height)

Description

compress

Declaration

public static Bitmap compress(String filePath, int width, int height) 

Method Source Code



import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import android.graphics.Matrix;

public class Main {

    public static Bitmap compress(String filePath, int width, int height) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);

        int bmpWidth = options.outWidth;
        int bmpHeight = options.outHeight;

        options.inJustDecodeBounds = false;
        bitmap = BitmapFactory.decodeFile(filePath, options);

        float scaleWidth = bmpWidth;
        float scaleHeight = bmpHeight;

        //  w ww.j  a va  2  s.c  o  m
        if (bmpWidth > width) {
            scaleWidth = width / scaleWidth;
        } else {
            scaleWidth = 1;
        }

        
        if (bmpHeight > height) {
            scaleHeight = height / scaleHeight;
        } else {
            scaleHeight = 1;
        }

        Matrix matrix = new Matrix();

        matrix.postScale(scaleWidth, scaleHeight);
        Bitmap resizeBitmap = Bitmap.createBitmap(bitmap, 0, 0, bmpWidth,
                bmpHeight, matrix, false);

        
        
        if (bitmap != resizeBitmap) {
            bitmap.recycle();
        }
        return resizeBitmap;
    }
}

Related

  1. zipFileAtPath(String[] sourcePaths, String toLocation)
  2. zipFileAtPath(final String sourcePath, final String toLocation)
  3. zipDirectory(File directory, File zip)
  4. zipDirectory(File directory, File zip)
  5. zipDirectory(File folder, String parentFolder, ZipOutputStream zos)
  6. compress(String paramString)
  7. compress(String path)
  8. compress(String path)
  9. compress(String path, boolean delete)