2016-12-16 23 views
0

WebP的支持作爲我們基於網絡的應用程序愛上WEBP圖片格式,我發現我需要一個方法或可對其進行解碼一個lib的自我,爲Java

我寫這一段代碼,但它只是忽略了本地解碼器(我曾經多麼喜歡它是廣口瓶LIB):

public BufferedImage decodeWebP(byte[] encoded, int w, int h) { 
    int[] width = new int[]{w}; 
    int[] height = new int[]{h}; 

    byte[] decoded = decodeRGBAnative(encoded); //here is the missing part , 
    if (decoded.length == 0) return null; 

    int[] pixels = new int[decoded.length/4]; 
    ByteBuffer.wrap(decoded).asIntBuffer().get(pixels); 

    BufferedImage bufferedImage = new BufferedImage(width[0], height[0], BufferedImage.TYPE_INT_RGB); 

    // bufferedImage.setRGB(x, y, your_value); 

    int BLOCK_SIZE = 3; 

    for(int r=0; r< height[0]; r++) { 
     for (int c = 0; c < width[0]; c++) { 
      int index = r * width[0] * BLOCK_SIZE + c * BLOCK_SIZE; 
      int red = pixels[index] & 0xFF; 
      int green = pixels[index + 1] & 0xFF; 
      int blue = pixels[index + 2] & 0xFF; 
      int rgb = (red << 16) | (green << 8) | blue; 
      bufferedImage.setRGB(c, r, rgb); 
     } 
    } 
    return bufferedImage; 
} 
+1

你在尋求什麼幫助來實現?請更清楚地定義你的問題/問題。 –

+0

http://stackoverflow.com/questions/17861601/webp-library-for-java –

+0

我需要一個webp解碼器,作爲一種方法或lib隊友。有些東西,我可以打開webp圖像與 – Reza

回答