create Bitmap Compress Options - Android Graphics

Android examples for Graphics:Bitmap Compress

Description

create Bitmap Compress Options

Demo Code


//package com.book2s;

import android.graphics.BitmapFactory;

public class Main {

    private static BitmapFactory.Options createCompressOptions(
            BitmapFactory.Options options, float targetHeight,
            float targetWidth) {
        options.inJustDecodeBounds = false;
        int w = options.outWidth;
        int h = options.outHeight;
        int be = 1;
        if (w > h && w > targetWidth) {
            be = (int) (options.outWidth / targetWidth);
        } else if (w < h && h > targetHeight) {
            be = (int) (options.outHeight / targetHeight);
        }/*from w  ww  . j a  v  a 2s.  c  o m*/
        if (be <= 0)
            be = 1;

        options.inSampleSize = be;
        return options;
    }
}

Related Tutorials