Monday, December 12, 2011

Could Modify View!

Just figured out how to modify the view on the canvas of the SurfaceView Class! So excited!

Instead of using onDraw() function directly in the CameraPreviewView(which inherits from SurfaceView), I used Handler to post the update() function in the ViewGroup, and the ViewGroup's update() function calls the update() function in CameraPreviewView class. Here, it calls postInvalidate() function which calls onDraw().

The pipeline is from this link(sorry it is in Chinese, but the code works well to display a blue box moving from the left to the right of the screen): http://l12052124.iteye.com/blog/745232

On the other hand, I created a Bitmap variable in the CameraPreviewView class and update it to the bitmap which comes from the camera's modified preview data. The class's onDraw() function directly draw this Bitmap to the UI. That works!

However, since all of the operations are based on CPU, the frame rate is still low. But here comes the core part!

Two question left: The algorithm I am using to convert camera preview data to Bitmap converts the data to RGBA, but the values for RGB are in the range of 0 to 262143, which is 512 * 512 - 1, instead of 0 to 256.

And, how does postDelayed() function work in the update?

Could anyone shed some light on them? Thanks! Cheers! Move On!

No comments:

Post a Comment