我有一个代表颜色的 MxN 整数数组(比如 RGBA 格式,但很容易更改)。我想将它们转换为 MxN 位图或我可以渲染到屏幕的其他内容(例如 OpenGL 纹理)。有没有快速的方法来做到这一点?遍历数组并将它们绘制到 Canvas 上太慢了。
最佳答案
试试这个,它会给你位图:
// You are using RGBA that's why Config is ARGB.8888
bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
// vector is your int[] of ARGB
bitmap.copyPixelsFromBuffer(IntBuffer.wrap(vector));
或者您可以从以下 native 方法生成 IntBuffer
:
private IntBuffer makeBuffer(int[] src, int n) {
IntBuffer dst = IntBuffer.allocate(n*n);
for (int i = 0; i < n; i++) {
dst.put(src[i]);
}
dst.rewind();
return dst;
}
关于java - 在 Android 上将 int 数组转换为位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7850185/