为int数组转换为位图在Android [英] Converting array of int to Bitmap on Android

查看:197
本文介绍了为int数组转换为位图在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有整型重新presenting颜色的M×N个阵列(比如RGBA格式,但这是很容易改变的)。我想将它们转换为M×N个位图或其他的东西(如一个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));

编辑:

 //OR , you can generate IntBuffer from 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);
        }
        dst.rewind();
        return dst;
    }*/

希望它会帮助你。

Hope it will help you .

这篇关于为int数组转换为位图在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆