所有,Android上的位圖提高getpixel的速度()和setpixel()
後,我注意到,如何慢getPixel
setPixel
是(不知道哪一個,估計都沒有渦輪增壓)我趕緊編碼的容器Bitmap
使用int[]
數組來處理位圖操作。
已經 - 它明顯更快,但這還不夠。請你能建議如何進一步加快速度?
我的想法是由setPixel
功能來跟蹤哪些是由「髒」和更新的Bitmap
只有這部分時getBitmap()
叫...如何設置setPixels
參數,但(一些與偏移不明確,我猜)。
另外 - 任何更快的食譜?
感謝您提前提供所有幫助!
import android.graphics.Bitmap;
public class DrawableBitmapContainer {
private Bitmap image;
private int width, height;
private int[] pixels;
public DrawableBitmapContainer(Bitmap _source){
image = _source;
width = image.getWidth();
height = image.getHeight();
pixels = new int[width*height];
image.getPixels(pixels,0,width,0,0,width,height);
}
public int getPixel(int x,int y){
return pixels[x+y*width];
}
public void setPixel(int x,int y, int color){
pixels[x+y*width]=color;
}
public Bitmap getBimap(){
image.setPixels(pixels,0,width,0,0,width,height);
return image;
}
public int getWidth(){
return image.getWidth();
}
public int getHeight(){
return image.getHeight();
}
}
我希望你認識到你的位圖需要2X的內存足跡,而且你的setpixel不起作用。這個數組只是實際位圖中圖像矩陣的副本。因此,通過更改其中的值,直到將該緩衝區提交回位圖對象後,它們纔會持續保留。 –
我瞭解它的兩倍內存(值得我使用的速度),但我迷失了你的評論setpixel不起作用 - 它的作品,如果我通過getBitmap方法訪問位圖,這就是我想要的。 – Piotr