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 getBitmap(String path) {
    try {//w  ww  . j a v a  2 s .c o m
        return BitmapFactory.decodeFile(path);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static String imgsToBase64(String filePath) {
    Bitmap bitmap = BitmapFactory.decodeFile(filePath);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    String lastName = filePath.substring(filePath.lastIndexOf(".") + 1);
    if (lastName.equals(Bitmap.CompressFormat.JPEG)) {
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
    } else {/*  w w w .  j  a v a2s.  c o m*/
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
    }
    return Base64.encodeToString(outputStream.toByteArray(), Base64.DEFAULT);
}

From source file:Main.java

public static void setImageBitmapFromFile(ImageView v, String path) {
    Bitmap bm = BitmapFactory.decodeFile(path);
    v.setImageBitmap(bm);
}

From source file:Main.java

public static void compressIt(String inputFile, String outputFile) {
    try {/* w  ww. j a  v a 2  s . c  o m*/
        Bitmap bmp = BitmapFactory.decodeFile(inputFile);
        FileOutputStream out = new FileOutputStream(new File(outputFile));
        bmp.compress(Bitmap.CompressFormat.PNG, 50, out); //100-best quality
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static String openAsBase64(String imgPath) {
    Bitmap photo = BitmapFactory.decodeFile(imgPath);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    photo.compress(Bitmap.CompressFormat.JPEG, 85, baos);
    byte[] b = baos.toByteArray();
    photo.recycle();/*from w w  w . j  ava  2 s. c o  m*/
    return Base64.encodeToString(b, Base64.DEFAULT);

}

From source file:Main.java

public static Bitmap fileToBitmap(String filepath) {
    File file = new File(filepath);
    if (file.exists()) {
        Bitmap bitmap = BitmapFactory.decodeFile(filepath);
        return bitmap;
    }/*from w w w .j  a v a  2  s.c o  m*/
    return null;
}

From source file:Main.java

public static Bitmap getImageFromLocal(String imagePath) {
    File file = new File(imagePath);
    if (file.exists()) {
        Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
        file.setLastModified(System.currentTimeMillis());
        return bitmap;
    }/* w ww  .  j a  v a 2  s. co m*/
    return null;
}

From source file:Main.java

public static Bitmap loadBitmap(String filename) throws Exception {
    return BitmapFactory.decodeFile(sAppContext.getCacheDir().getPath() + "/" + filename);
}

From source file:Main.java

public static boolean isFileBiggerThan1MB(String filePath) {
    File f = new File(filePath);

    Bitmap bitmap;/*from   w w w  .ja  v  a  2s .  co m*/
    bitmap = BitmapFactory.decodeFile(filePath);
    int MAX_IMAGE_SIZE = 1000 * 1024;
    int streamLength = (int) f.length();
    return streamLength >= MAX_IMAGE_SIZE;
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static Drawable getConvertDrawable(String filepath) {
    Bitmap bitmap = BitmapFactory.decodeFile(filepath);
    Drawable drawable = new BitmapDrawable(bitmap);
    return drawable;
}