0

次のように、Google PlayStoreから WEBP アイコンを取得して表示しようとしています。

データを直接使用してBitmapFactoryでデコードしようとしました(時々動作します...)、libwebpでも試しましたが、「WebPGetInfo」関数でデータをテストすると0が返されます(つまり、データは webp image . ..)

libwebp で使用するコードは次のとおりです。

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;

    }

ありがとうございます。

編集:複数の変更の後、libwebp を使用すると NoClassDefFoundError が発生するようになりました...

4

0 に答える 0