android fast pixel access and manipulation

前端 未结 4 987
别那么骄傲
别那么骄傲 2021-02-06 02:06

I\'m trying to port an emulator that i have written in java to android. Things have been going nicely, I was able to port most of my codes with minor changes however due to how

4条回答
  •  伪装坚强ぢ
    2021-02-06 02:41

    Don't recreate the bitmap every single time. Try something like this:

    Bitmap buffer = null;
    @Override
    public void onDraw(Canvas canvas)
    {
        if(buffer == null) buffer = Bitmap.createBitmap(256, 192, Bitmap.Config.RGB_565);
        buffer.copyPixelsFromBuffer(pixelsA);
        canvas.drawBitmap(buffer, 0, 0, null);
    }
    

    EDIT: as pointed out, you need to update the pixel buffer. And the bitmap must be mutable for that to happen.

提交回复
热议问题