Android Bitmap Load loadPreviewBitmap(String fileName, int width, int height)

Here you can find the source of loadPreviewBitmap(String fileName, int width, int height)

Description

200px PreviewBitmap

Parameter

Parameter Description
fileName a parameter

Declaration

public static Bitmap loadPreviewBitmap(String fileName, int width,
        int height) 

Method Source Code

//package com.java2s;
import java.io.File;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

public class Main {
    /**/*from   www  .  ja v  a 2 s . c  om*/
     * 200px PreviewBitmap
     * 
     * @param fileName
     * @return
     */
    public static Bitmap loadPreviewBitmap(String fileName, int width,
            int height) {
        try {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = false;
            options.inSampleSize = 1;
            File file = new File(fileName);
            if (!file.exists()) {
                return null;
            }
            if (file.length() > 4 * 1024 * 1024) {
                options.inSampleSize = 4;
            } else if (file.length() > 1024 * 1024) {
                options.inSampleSize = 2;
            }
            Bitmap bm = BitmapFactory.decodeFile(fileName, options);
            if (bm != null) {
                Bitmap resizebm = resizePreviewBitmap(bm, width, height);
                bm.recycle();
                return resizebm;
            }
            return null;
        } catch (OutOfMemoryError e) {
            return null;
        }
    }

    public static Bitmap resizePreviewBitmap(Bitmap bm, int width,
            int height) {
        try {
            if (bm != null) {
                Bitmap resizebm = Bitmap.createScaledBitmap(bm, width,
                        height, true);
                return resizebm;
            } else {
                return null;
            }
        } catch (OutOfMemoryError e) {
            return null;
        }
    }
}

Related

  1. loadBitmapAsset(Context context, String asset)
  2. loadBitmapFromAssets(Context context, String name)
  3. loadBitmapFromStorage(String path)
  4. loadImage(String filename)
  5. loadImage(String urlStr)
  6. SafeDecodeBitmapFile( String strFilePath)
  7. decodeF(File f)
  8. decodeFile(File f, int size)
  9. decodeFromDescriptor( FileDescriptor descriptor)