Example usage for android.graphics BitmapFactory decodeStream

List of usage examples for android.graphics BitmapFactory decodeStream

Introduction

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

Prototype

public static Bitmap decodeStream(InputStream is) 

Source Link

Document

Decode an input stream into a bitmap.

Usage

From source file:Main.java

public static Bitmap bitmapFromFile(File file) throws FileNotFoundException {
    return BitmapFactory.decodeStream(new BufferedInputStream(new FileInputStream(file)));
}

From source file:Main.java

public static Bitmap getBitmap(String uri) {
    try {//from w  ww.  j  a va 2s.c  om
        InputStream is = new URL(uri).openStream();
        return BitmapFactory.decodeStream(is);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static Bitmap loadBitmapFromAssets(Context context, String name) {
    try {// ww  w.  j a v  a  2  s.  com
        InputStream is = context.getAssets().open(name);
        Bitmap bitmap = BitmapFactory.decodeStream(is);
        return bitmap;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static Bitmap LoadImageFromWeb(String url) {
    try {//from   ww  w  . j av  a2s. com
        String encodedurl = url.replace(" ", "%20");
        InputStream is = (InputStream) new URL(encodedurl).getContent();
        Bitmap d = BitmapFactory.decodeStream(is);
        return d;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static Bitmap getBitmap(Context context, String path) {
    InputStream ins = null;//from   ww  w.  j  a v a  2  s .c o m
    Bitmap bitmap = null;
    try {
        ins = context.getAssets().open(path);
        bitmap = BitmapFactory.decodeStream(ins);
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
    return bitmap;
}

From source file:Main.java

private static Bitmap decodeBitmap(Context context, String frameName, int position) {
    try {/*from  w w w  . j av  a  2s  .  c  o m*/
        switch (position) {
        case 0:
            return BitmapFactory.decodeStream(context.getAssets().open("frames/" + frameName + "/leftup.png"));
        case 1:
            return BitmapFactory.decodeStream(context.getAssets().open("frames/" + frameName + "/left.png"));
        case 2:
            return BitmapFactory
                    .decodeStream(context.getAssets().open("frames/" + frameName + "/leftdown.png"));
        case 3:
            return BitmapFactory.decodeStream(context.getAssets().open("frames/" + frameName + "/down.png"));
        case 4:
            return BitmapFactory
                    .decodeStream(context.getAssets().open("frames/" + frameName + "/rightdown.png"));
        case 5:
            return BitmapFactory.decodeStream(context.getAssets().open("frames/" + frameName + "/right.png"));
        case 6:
            return BitmapFactory.decodeStream(context.getAssets().open("frames/" + frameName + "/rightup.png"));
        case 7:
            return BitmapFactory.decodeStream(context.getAssets().open("frames/" + frameName + "/up.png"));
        default:
            return null;
        }
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static Bitmap getBitmapFromAssets(Context context, String fileName) {
    try {//from   www  .  j a  v  a  2s.com

        InputStream inputStream = context.getAssets().open(fileName);

        return BitmapFactory.decodeStream(inputStream);
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:Main.java

public static Bitmap loadImageFromNet_throw(String url) throws IOException {
    URL m;// w  w w.  j av a2  s .  c  o m
    InputStream i = null;

    m = new URL(url);
    i = (InputStream) m.getContent();

    return BitmapFactory.decodeStream(i);
}

From source file:Main.java

public static Bitmap getAssetBitmap(Context context, String path) {
    Bitmap mBitmap = null;/*from w w  w  .j  a v  a  2  s  . c om*/
    try {
        InputStream is = context.getAssets().open(path);
        mBitmap = BitmapFactory.decodeStream(is);
        is.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return mBitmap;
}

From source file:Main.java

public static Bitmap loadBitmapFromAsset(Context context, String path) throws IOException {
    InputStream ims = context.getAssets().open(path);

    return BitmapFactory.decodeStream(ims);
}