Here you can find the source of loadPreviewBitmap(String fileName, int width, int height)
Parameter | Description |
---|---|
fileName | a parameter |
public static Bitmap loadPreviewBitmap(String fileName, int width, int height)
//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; } } }