android fast pixel access and manipulation

前端 未结 4 993
别那么骄傲
别那么骄傲 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:31

    One quite low-level method, but working fine for me (with native code):

    Create Bitmap object, as big as your visible screen. Also create a View object and implement onDraw method.

    Then in native code you'd load libjnigraphics.so native library, lookup functions AndroidBitmap_lockPixels and AndroidBitmap_unlockPixels. These functions are defined in Android source in bitmap.h.

    Then you'd call lock/unlock on a bitmap, receiving address to raw pixels. You must interpret RGB format of pixels accordingly to what it really is (16-bit 565 or 32-bit 8888).

    After changing content of the bitmap, you want to present this on screen. Call View.invalidate() on your View. In its onDraw, blit your bitmap into given Canvas.

    This method is very low level and dependent on actual implementation of Android, however it's very fast, you may get 60fps no problem.

    bitmap.h is part of Android NDK since platform version 8, so this IS official way to do this from Android 2.2.

提交回复
热议问题