Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I do not think you are downloading properly the bitmap.</p> <p><strong>CODE</strong></p> <p>This is a function I created that will take a url from you and it will return a drawable! It will save it to a file and get it if it exists</p> <p>If not, it will download it and return the drawable. <strong><em>You can easily edit it to save file to your folder instead.</em></strong></p> <pre><code>/** * Pass in an image url to get a drawable object * * @return a drawable object */ private static Drawable getDrawableFromUrl(final String url) { String filename = url; filename = filename.replace("/", "+"); filename = filename.replace(":", "+"); filename = filename.replace("~", "s"); final File file = new File(Environment.getExternalStorageDirectory() + File.separator + filename); boolean exists = file.exists(); if (!exists) { try { URL myFileUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection) myFileUrl .openConnection(); conn.setDoInput(true); conn.connect(); InputStream is = conn.getInputStream(); final Bitmap result = BitmapFactory.decodeStream(is); is.close(); new Thread() { public void run() { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); result.compress(Bitmap.CompressFormat.JPEG, 40, bytes); try { if (file.createNewFile()){ // } else{ // } FileOutputStream fo; fo = new FileOutputStream(file); fo.write(bytes.toByteArray()); fo.flush(); fo.close(); } catch (IOException e) { e.printStackTrace(); } } }.start(); BitmapDrawable returnResult = new BitmapDrawable(result); return returnResult; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } else { return new BitmapDrawable(BitmapFactory.decodeFile(file.toString())); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload