本文介紹了在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數組轉換為位圖的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!