Example usage for android.graphics BitmapFactory decodeFile

List of usage examples for android.graphics BitmapFactory decodeFile

Introduction

In this page you can find the example usage for android.graphics BitmapFactory decodeFile.

Prototype

public static Bitmap decodeFile(String pathName) 

Source Link

Document

Decode a file path into a bitmap.

Usage

From source file:Main.java

public static Bitmap decodeBitmapFromFileToSize(String filePath, int reqWidth, int reqHeight,
        boolean maintainAspectRatio) {
    Bitmap original = BitmapFactory.decodeFile(filePath);
    if (original == null) {
        return null;
    }// ww  w  .  j  ava  2  s.c om
    if (original.getWidth() == reqWidth || original.getHeight() == reqHeight) {
        return original;
    }

    if (maintainAspectRatio) {
        int oriWidth = original.getWidth(), oriHeight = original.getHeight();
        if (oriWidth >= oriHeight) {
            float aRatio = (float) oriHeight / (float) oriWidth;
            reqHeight = (int) (reqWidth * aRatio);
        } else if (oriHeight > oriWidth) {
            float aRatio = (float) oriWidth / (float) oriHeight;
            reqWidth = (int) (reqHeight * aRatio);
        }
    }

    Bitmap scaled = Bitmap.createScaledBitmap(original, reqWidth, reqHeight, false);
    if (scaled == null) {
        return original;
    }
    if (scaled != original) {
        original.recycle();
        original = null;
    }
    return scaled;
}

From source file:Main.java

public static Bitmap getIconForAppPath(Context context) {
    String path = context.getFilesDir().getPath() + "/crop.png";
    File file = new File(path);
    if (file.exists()) {
        return BitmapFactory.decodeFile(path);
    }//from   w  w w .  j av a  2  s  .c  o m
    return null;
}

From source file:Main.java

public static Bitmap getBitmap(String name) {
    String path = Environment.getExternalStorageDirectory().getPath() + "/Chaoke/" + name;
    System.out.println(Environment.getExternalStorageDirectory().getPath() + "/Chaoke/" + name);
    return BitmapFactory.decodeFile(path);
}

From source file:Main.java

public static Bitmap getDiskBitmap(String pathString) {
    Bitmap bitmap = null;/*www  .j  av  a2s  .co m*/
    try {
        File file = new File(pathString);
        if (file.exists()) {
            bitmap = BitmapFactory.decodeFile(pathString);
        }
    } catch (Exception e) {
        // TODO: handle exception  
    }

    return bitmap;
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static Drawable getDrawableFromFile(File pngFile, int density) {
    Bitmap bmp = BitmapFactory.decodeFile(pngFile.getPath());
    bmp.setDensity(density);/*w w w. j  a v a 2  s.  co m*/

    return new BitmapDrawable(bmp);
}

From source file:Main.java

public static void initializeFiles(List<String> filePathNameList, List<Bitmap> imageBitMaps, int offset,
        int size) {
    for (int i = 0; i < (offset + size); i++) {
        if (new File(filePathNameList.get(i)).exists()) {
            imageBitMaps.add(BitmapFactory.decodeFile(filePathNameList.get(i)));
        }/*from   ww  w  .ja  va2  s  .  c  o  m*/
    }
}

From source file:Main.java

public static Bitmap getBitmapFromLocal(String fileName) {
    Bitmap bitmap = null;/*from   w ww .  jav a2 s.co m*/
    String pathName = Environment.getExternalStorageDirectory() + "/boc_container/" + fileName;
    File file = new File(pathName);
    if (file.exists()) {
        bitmap = BitmapFactory.decodeFile(pathName);
    }
    return bitmap;
}

From source file:Main.java

public static Bitmap getRotatedImg(String path) {
    int angle = getBitmapRotation(path);
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);//from   ww  w . j a  va 2  s.  co m
    Bitmap bitmap = BitmapFactory.decodeFile(path);
    try {
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return bitmap;
}

From source file:Main.java

public static Bitmap getImg(String url) {
    if (!isMounted())
        return null;

    File imgFile = new File(CACHEDIR, getName(url));
    if (imgFile.exists()) {
        return BitmapFactory.decodeFile(imgFile.getAbsolutePath());
    }//from   www .j av  a  2 s  .  c  om

    return null;
}

From source file:Main.java

public static Bitmap loadFromFile(String filename) {
    try {/*from ww  w .  j ava  2  s  .  c  o  m*/
        File f = new File(filename);
        if (!f.exists()) {
            return null;
        }
        Bitmap tmp = BitmapFactory.decodeFile(filename);
        return tmp;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}