Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay WEBP image on android from URL
    primarykey
    data
    text
    <p>I'm trying to get and display a WEBP icon from Google PlayStore, like this one : <a href="http://lh5.ggpht.com/YK0as9_ZRmSK6PBkSwRVQ62F5cBMq7gYMLfZ2nk30QjEVK6taYMPMKzh0eswMkBMhw=w170-rw" rel="nofollow">http://lh5.ggpht.com/YK0as9_ZRmSK6PBkSwRVQ62F5cBMq7gYMLfZ2nk30QjEVK6taYMPMKzh0eswMkBMhw=w170-rw</a></p> <p>I tried using directly the data and decoding it with BitmapFactory (works sometimes ...), I also tried with the libwebp but when I test the data with the "WebPGetInfo" function it returns 0 (wich means the datas are not webp image ...)</p> <p>Here is the code I use with libwebp:</p> <pre><code>public static Bitmap getBitmapFromURL(String src) { HttpURLConnection connection = null; Bitmap bmp = null; try { connection = (HttpURLConnection) new URL(src).openConnection(); connection.setRequestMethod("GET"); connection.setUseCaches(false); connection.setDoInput(true); connection.setDoOutput(true); connection.setRequestProperty("Content-Type", "image/webp"); connection.connect(); //Send request DataOutputStream wr = new DataOutputStream ( connection.getOutputStream ()); wr.writeBytes (""); wr.flush (); wr.close (); //Get Response BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[4096]; while(true) { String n = rd.readLine(); if(n == null)break; baos.write(n.getBytes(), 0, n.getBytes().length); baos.write('\n'); } byte data[] = baos.toByteArray(); // From the lib's exemple int[] width = new int[] { 0 }; int[] height = new int[] { 0 }; int test = libwebp.WebPGetInfo(data, data.length, width, height); // test = 0 ! ! ! byte[] decoded = libwebp.WebPDecodeARGB(data, data.length, width, height); int[] pixels = new int[decoded.length / 4]; ByteBuffer.wrap(decoded).asIntBuffer().get(pixels); bmp = Bitmap.createBitmap(pixels, width[0], height[0], Bitmap.Config.ARGB_8888); } catch (IOException e) { e.printStackTrace(); } return bmp; } </code></pre> <p>Thx for your help.</p> <p>EDIT : After multiple changes I now have a NoClassDefFoundError when using libwebp ...</p>
    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. 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