decode File to create Bitmap - Android Graphics

Android examples for Graphics:Bitmap File

Description

decode File to create Bitmap

Demo Code


//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

public class Main {
    public static Bitmap decodeFile(String path) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;

        BitmapFactory.decodeFile(path, options);

        int scaleW = options.outWidth / 380 + 1;
        int scaleH = options.outHeight / 420 + 1;

        int scale = Math.max(scaleW, scaleH);

        options.inJustDecodeBounds = false;

        options.inSampleSize = scale;//from  w w w. j a  v a2s . c o  m
        Bitmap image = BitmapFactory.decodeFile(path, options);

        return image;
    }
}

Related Tutorials