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:com.github.chenxiaolong.dualbootpatcher.switcher.CacheRomThumbnailTask.java

private Bitmap createThumbnailFromUri(Uri uri) {
    try {/*ww w .jav  a 2  s.co m*/
        InputStream input = mContext.getContentResolver().openInputStream(uri);
        Bitmap bitmap = BitmapFactory.decodeStream(input);
        input.close();

        if (bitmap == null) {
            return null;
        }

        return ThumbnailUtils.extractThumbnail(bitmap, 500, 500);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:com.krayzk9s.imgurholo.tools.LoadImageAsync.java

@Override
protected Bitmap doInBackground(Void... voids) {
    try {//from w w w  . ja v  a2  s .c om
        URL url;
        if (imageData.getJSONObject().has(ImgurHoloActivity.IMAGE_DATA_COVER))
            url = new URL("http://imgur.com/"
                    + imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_COVER) + ".png");
        else
            url = new URL(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK));
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.connect();
        InputStream input = connection.getInputStream();
        return BitmapFactory.decodeStream(input);
    } catch (JSONException e) {
        Log.e("Error!", e.toString());
    } catch (IOException e) {
        Log.e("Error!", e.toString());
    } catch (OutOfMemoryError e) {
        Log.e("Error!", e.toString());
    }

    return null;
}

From source file:jp.co.ipublishing.esnavi.dependence.shelter.ShelterImageFactory.java

/**
 * NO IMAGE ???//from  w  w  w .j  a  v  a  2 s .c  o  m
 *
 * @return NO IMAGE?
 */
private Bitmap getNoImageBitmap(Context context) {
    try {
        final InputStream is = context.getResources().getAssets().open("shelter_images/noimage.png");
        final Bitmap bmp = BitmapFactory.decodeStream(is);
        is.close();
        return bmp;
    } catch (IOException e) {
        Log.e(TAG, ExceptionUtils.getStackTrace(e));
    }
    return null;
}

From source file:com.limewoodmedia.nsdroid.LoadingHelper.java

public static Bitmap loadFlag(String url, Context context) throws ClientProtocolException, IOException {
    if (url == null || url.length() == 0) {
        // No flag to load
        return null;
    }//from w w  w.  j a v a2  s .  co  m
    HttpClient client = new DefaultHttpClient();
    client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, API.getInstance(context).getUserAgent());
    client.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
    HttpGet get = new HttpGet(url);
    HttpResponse response = client.execute(get);
    InputStream stream = response.getEntity().getContent();
    return BitmapFactory.decodeStream(stream);
}

From source file:org.imaginationforpeople.android2.model.Picture.java

public Bitmap getThumbBitmap() {
    if (thumbBitmap == null) {
        String path;/*from www . j  a  v  a 2s.c  o  m*/
        try {
            path = new URL(thumbUrl).getPath();
            if (DataHelper.checkThumbFile(thumbUrl)) {
                FileInputStream file = DataHelper.openFileInput(
                        DataHelper.FILE_PREFIX_PROJECT_THUMB + path.substring(path.lastIndexOf('/') + 1));
                thumbBitmap = BitmapFactory.decodeStream(file);
            } else
                return null;
        } catch (MalformedURLException e) {
            e.printStackTrace();
            return null;
        }
    }
    return thumbBitmap;
}

From source file:eu.loopit.f2011.library.BitmapManager.java

public Bitmap fetchBitmap(String urlString, final Bitmap defaultImage) {
    UUID uuid = UUID.nameUUIDFromBytes(urlString.getBytes());
    if (bitmapMap.containsKey(uuid)) {
        return bitmapMap.get(uuid);
    }//  w ww .  j  a va  2 s .c o  m

    Log.d(TAG, "image url:" + urlString);
    InputStream is = null;
    try {
        is = fetch(uuid);
        if (is == null)
            is = fetch(urlString);
        Bitmap bitmap = BitmapFactory.decodeStream(is);
        if (bitmap == null && defaultImage == null) {
            Log.i(TAG, "Could not load: " + urlString);
            return null;
        }
        bitmapMap.put(uuid, bitmap != null ? bitmap : defaultImage);
        Log.d(TAG, "Got Bitmap: " + urlString);
        return bitmapMap.get(uuid);
    } catch (MalformedURLException e) {
        Log.e(TAG, "fetchBitmap failed", e);
        return null;
    } catch (IOException e) {
        Log.e(TAG, "fetchBitmap failed", e);
        return null;
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                Log.e(TAG, "Could not close stream for URL" + urlString, e);
            }
        }
    }
}

From source file:forplay.android.AndroidAssetManager.java

@Override
protected Image doGetImage(String path) {
    try {/*from w w w  .  ja  v  a2s  .co m*/
        InputStream is = openResource(path);
        if (is == null) {
            // TODO: This should return an error image like JavaAssetManager does
            throw new RuntimeException("Unable to load image " + path);
        }
        try {
            return new AndroidImage(path, BitmapFactory.decodeStream(is));
        } finally {
            is.close();
        }
    } catch (IOException e) {
        // TODO: This should return an error image like JavaAssetManager does
        throw new RuntimeException(e);
    }
}

From source file:ca.marcmeszaros.papyrus.remote.DownloadThumbnails.java

@Override
protected LinkedList<Bitmap> doInBackground(URL... urls) {

    // some class variables
    HttpGet httpRequest;// w  ww.  j  a v a 2s  .c  o  m
    Bitmap bm;
    LinkedList<Bitmap> bitmaps = new LinkedList<Bitmap>();

    try {

        // loop through all urls
        for (URL url : urls) {
            // create the HTTP request
            httpRequest = new HttpGet(url.toURI());

            // create an HTTP client and get the response
            HttpClient httpclient = new DefaultHttpClient();
            HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);

            // get a handle on the http entity
            HttpEntity entity = response.getEntity();
            BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
            InputStream instream = bufHttpEntity.getContent();

            // read the entity from the stream into a bitmap object
            bm = BitmapFactory.decodeStream(instream);

            // add the bitmap to the list
            bitmaps.add(bm);

        }

    } catch (URISyntaxException e) {
        Log.e(TAG, "URISyntaxException", e);
    } catch (ClientProtocolException e) {
        Log.e(TAG, "ClientProtocolException", e);
    } catch (IOException e) {
        Log.e(TAG, "IOException", e);
    }

    return bitmaps;
}

From source file:it.agileday.utils.HttpRestUtil.java

public static Bitmap httpGetBitmap(String url) {
    final HttpClient client = new DefaultHttpClient();
    final HttpGet getRequest = new HttpGet(url);

    try {/*from ww w  . java2  s  .c  o m*/
        HttpResponse response = client.execute(getRequest);
        final int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            Log.w(TAG, "Error " + statusCode + " while retrieving bitmap from " + url);
            return null;
        }

        final HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream inputStream = null;
            try {
                inputStream = entity.getContent();
                final Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
                return bitmap;
            } finally {
                if (inputStream != null) {
                    inputStream.close();
                }
                entity.consumeContent();
            }
        }
    } catch (Exception e) {
        getRequest.abort();
        Log.w(TAG, "Error while retrieving bitmap from " + url, e);
    }
    return null;
}

From source file:com.uzmap.pkg.uzmodules.UIListView.data.Utils.java

public static Bitmap getBitmapFromLocal(String path, UZWidgetInfo wInfo) {
    if (TextUtils.isEmpty(path)) {
        return null;
    }//from   w w  w .  ja  v  a 2s. c  o  m

    String realPath = UZUtility.makeRealPath(path, wInfo);
    InputStream input = null;
    Bitmap bitmap = null;
    try {
        input = UZUtility.guessInputStream(realPath);
        bitmap = BitmapFactory.decodeStream(input);
        if (input != null) {
            input.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return bitmap;
}