get Picture Bitmap by id - Android Graphics

Android examples for Graphics:Bitmap File

Description

get Picture Bitmap by id

Demo Code


//package com.java2s;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Main {
    public static Bitmap getPicBitmap(Resources res, int id, int picWidth) {
        // TODO Auto-generated method stub
        picWidth = picWidth - 50;/* w  w  w  .j  a v a  2 s.  c  om*/
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        Bitmap bmp = BitmapFactory.decodeResource(res, id, options);
        double height = options.outHeight;
        double width = options.outWidth;
        double picScale = height / width;
        //      options.outWidth = height;
        //      options.outHeight = (int) (10 * picScale);
        options.inJustDecodeBounds = false;
        bmp = BitmapFactory.decodeResource(res, id, options);

        return bmp;
    }
}

Related Tutorials