我试图抓住一组mipmaplevels并保存到本地缓存文件,以避免每次重建它们(并且预先生成它们是不现实的......)android bytebuffer as intbuffer - asarray总是给予不支持的操作
我已经将mipmaplevels集成到一组位图中,现在想将它们写入到我的缓存文件中,但是无论使用何种缓冲区(直接或不是,设置字节序或不),hasArray总是返回false在intbuffer上。我必须在这里做一些愚蠢的事情,但我再也看不到树木了。
没有使用Java进行长时间,所以这是prolly一个小白错误;)
代码如下所示:
int tsize = 256;
ByteBuffer xbb = ByteBuffer.allocate(tsize*tsize*4);
// or any other variety of create like wrap etc. makes no diference
xbb.order(ByteOrder.nativeOrder()); // in or out - makes no difference
IntBuffer ib = xbb.asIntBuffer();
for (int i = 0; i < tbm.length; i++) {
//ib.array() throws exception, ib.hasArray() returns false;
tbm[i].getPixels(ib.array(), 0, tsize, 0, 0, tsize, tsize);
ou.write(xbb.array(), 0, tsize*tsize*4);
tsize = tsize/2;
}
使用bitmap.copypixels有点帮助,但仍然是更好的驱动IO不复制....... – pootle
仍在使用copypixels。有一天必须更加努力地寻求更好的答案! – pootle