List of usage examples for android.graphics BitmapFactory decodeStream
public static Bitmap decodeStream(InputStream is)
From source file:com.github.hobbe.android.openkarotz.util.AssetUtils.java
/** * Load a bitmap image from the asset filename. * @param context the context//from ww w.j a va2 s .c o m * @param filename the name of the image * @return the bitmap or {@code null} */ public static Bitmap loadBitmapFromAsset(Context context, String filename) { // Log.v(LOG_TAG, "Loading bitmap asset " + filename); Bitmap bmp = null; InputStream is = null; try { is = context.getAssets().open(filename); bmp = BitmapFactory.decodeStream(is); } catch (IOException e) { Log.e(LOG_TAG, "Could not load bitmap asset " + filename, e); return null; } finally { if (is != null) { try { is.close(); } catch (IOException e) { // Ignored } } } return bmp; }
From source file:com.wishlist.Utility.java
public static Bitmap getBitmap(String url) { Bitmap bm = null;//from w ww. j a v a2 s .c om try { URL aURL = new URL(url); URLConnection conn = aURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); bm = BitmapFactory.decodeStream(new FlushedInputStream(is)); bis.close(); is.close(); } catch (Exception e) { e.printStackTrace(); } finally { if (httpclient != null) { httpclient.close(); } } return bm; }
From source file:com.tweetlanes.android.core.URLFetch.java
public static void fetchBitmap(final String urlAsString, final FetchBitmapCallback callback) { Thread t = new Thread() { public void run() { URL url;//from ww w. java2 s .co m Bitmap bitmap = null; try { url = new URL(urlAsString); // Log.d("tweetlanes url fetch", urlAsString); URLConnection connection = url.openConnection(); connection.setUseCaches(true); Object response = connection.getContent(); if (response instanceof Bitmap) { bitmap = (Bitmap) response; } else { InputStream inputStream = connection.getInputStream(); bitmap = BitmapFactory.decodeStream(inputStream); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (callback != null) { callback.finished(bitmap != null ? true : false, bitmap); } } }; t.start(); }
From source file:com.shafiq.mytwittle.URLFetch.java
public static void fetchBitmap(final String urlAsString, final FetchBitmapCallback callback) { Thread t = new Thread() { @Override//from w w w. ja v a 2 s.co m public void run() { URL url; Bitmap bitmap = null; try { url = new URL(urlAsString); // Log.d("mytwittle url fetch", urlAsString); URLConnection connection = url.openConnection(); connection.setUseCaches(true); Object response = connection.getContent(); if (response instanceof Bitmap) { bitmap = (Bitmap) response; } else { InputStream inputStream = connection.getInputStream(); bitmap = BitmapFactory.decodeStream(inputStream); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (callback != null) { callback.finished(bitmap != null ? true : false, bitmap); } } }; t.start(); }
From source file:com.tweetlanes.android.URLFetch.java
public static void fetchBitmap(final String urlAsString, final FetchBitmapCallback callback) { Thread t = new Thread() { public void run() { URL url;/* w w w.j av a 2 s . co m*/ Bitmap bitmap = null; try { url = new URL(urlAsString); //Log.d("tweetlanes url fetch", urlAsString); URLConnection connection = url.openConnection(); connection.setUseCaches(true); Object response = connection.getContent(); if (response instanceof Bitmap) { bitmap = (Bitmap) response; } else { InputStream inputStream = connection.getInputStream(); bitmap = BitmapFactory.decodeStream(inputStream); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (callback != null) { callback.finished(bitmap != null ? true : false, bitmap); } } }; t.start(); }
From source file:de.dan_nrw.android.util.net.BitmapHttpResponseHandler.java
@Override protected Bitmap handleResponseInternal(HttpResponse response) throws IOException { return BitmapFactory.decodeStream(response.getEntity().getContent()); }
From source file:Main.java
public static Bitmap decodeBitmapFromURL(String src, boolean large) { // If the artwork returned null, don't want to try to show artwork if (src.equals("null")) { return null; }// w ww . j a v a 2 s . c om if (large) { src = src.replace("large", "t500x500"); } InputStream inputStream = null; try { URL url = new URL(src); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.connect(); inputStream = connection.getInputStream(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (inputStream == null) { return null; } // Decided not to scale because would have to recreate input stream /* final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(inputStream, null, options); options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); options.inJustDecodeBounds = false; */ Bitmap returnBitmap = BitmapFactory.decodeStream(inputStream); return returnBitmap; }
From source file:com.madgag.android.lazydrawables.gravatar.GravatarBitmapDownloader.java
public Bitmap get(String gravatarId) { InputStream is = downloadStreamFor(gravatarId); try {/* w ww . jav a 2 s .co m*/ return BitmapFactory.decodeStream(new FlushedInputStream(is)); } finally { closeQuietly(is); } }
From source file:ms.sujinkim.com.test.api.FoscamSnapshotRunnable.java
private void writeSnapshot(String name, InputStream stream) throws IOException { Bitmap bitmap = BitmapFactory.decodeStream(stream); ByteArrayOutputStream byteStream = null; FileOutputStream fileStream = null; try {//from ww w . j av a2 s .com byteStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteStream); File file = new File(Environment.getExternalStorageDirectory() + File.separator + name); file.createNewFile(); fileStream = new FileOutputStream(file); fileStream.write(byteStream.toByteArray()); } finally { if (byteStream != null) { byteStream.close(); } if (fileStream != null) { fileStream.close(); } } }
From source file:com.example.facebook_photo.Utility.java
public static Bitmap getBitmap(String url) { Bitmap bm = null;//from www . j a v a 2s . com try { URL aURL = new URL(url); URLConnection conn = aURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); bm = BitmapFactory.decodeStream(new FlushedInputStream(is)); bis.close(); is.close(); } catch (Exception e) { e.printStackTrace(); } finally { if (httpclient != null) { httpclient.close(); } } return bm; }