Android Bitmap Compress downsampleBitmap(FileDescriptor fd, int maxArea)

Here you can find the source of downsampleBitmap(FileDescriptor fd, int maxArea)

Description

downsample Bitmap

License

Open Source License

Declaration

public static Bitmap downsampleBitmap(FileDescriptor fd, int maxArea) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.FileDescriptor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import android.graphics.Rect;

public class Main {
    public static Bitmap downsampleBitmap(FileDescriptor fd, int maxArea) {
        BitmapFactory.Options opts = new BitmapFactory.Options();
        opts.inJustDecodeBounds = true;/*from  w  ww.j a  v a2  s . c  om*/

        Rect outRect = new Rect();
        BitmapFactory.decodeFileDescriptor(fd, outRect, opts);

        int subsample = 1;
        int width = opts.outWidth;
        int height = opts.outHeight;
        while (width * height > maxArea) {
            width /= 2;
            height /= 2;
            subsample++;
        }

        opts.inJustDecodeBounds = false;
        opts.inSampleSize = subsample;
        Bitmap retval = BitmapFactory.decodeFileDescriptor(fd, null, opts);
        return retval;
    }
}

Related

  1. compressBitmap(Bitmap bitmap)
  2. compressToBytes(Bitmap bitmap, int quality)
  3. compress(String srcPath, String dstPath, int maxWidth, int maxHeight, long maxSize, CompressFormat format)
  4. compress(byte[] data, String dstPath, int maxWidth, int maxHeight, long maxSize, CompressFormat format)
  5. decodeToCompressedByteArray(String imageUri)