private static ByteBuffer loadIcon(String path) throws IOException { InputStream inputStream = new FileInputStream(path); try { PNGDecoder decoder = new PNGDecoder(inputStream); ByteBuffer bytebuf = ByteBuffer.allocateDirect(decoder.getWidth()*decoder.getHeight()*4); decoder.decode(bytebuf, decoder.getWidth()*4, PNGDecoder.RGBA); bytebuf.flip(); return bytebuf; } finally { inputStream.close(); } }
private ByteBuffer loadIcon(String file) { try { InputStream is = Loader.getResourceAsStream(file); PNGDecoder decoder = new PNGDecoder(is); ByteBuffer bb = ByteBuffer.allocateDirect(decoder.getWidth() * decoder.getHeight() * 4); decoder.decode(bb, decoder.getWidth() * 4, PNGDecoder.RGBA); bb.flip(); is.close(); return bb; } catch (Exception e) { Log.stackTrace(e); return null; } }