本文介绍了在Android上将int数组转换为位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
我有一个表示颜色的 MxN 整数数组(比如 RGBA 格式,但很容易更改).我想将它们转换为可以渲染到屏幕的 MxN 位图或其他东西(例如 OpenGL 纹理).有没有快速的方法来做到这一点?循环遍历数组并将它们绘制到画布上太慢了.
I have an MxN array of ints representing colors (say RGBA format, but that is easily changeable). I would like to convert them to an MxN Bitmap or something else (such as an OpenGL texture) that I can render to the screen. Is there a fast way to do this? Looping through the array and drawing them to the canvas is far too slow.
推荐答案
试试这个,它会给你位图:
Try this, it will give you the bitmap:
// 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));
或者您可以从以下本地方法生成 IntBuffer
:
Or you can generate IntBuffer
from the following native method:
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;
}
这篇关于在Android上将int数组转换为位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!