views:

47

answers:

2

I have two images overlayed and i copy pixels from bottom image to top image while ACTION_MOVE. My goal is to give erasing feeling to the user but sometimes it doesn't copy(erase) some parts and it gets worse if touch event is fast( dragging finger fastly).

This is the code i am using for copying pixels

mutable.getPixels(pixels, 0, width, xPos,  yPos, width, height) ;
mutable2.setPixels(pixels, 0, width,xPos,  yPos, width, height) ;
+1  A: 

Store all the touch events in a queue and do the image manipulation in a second thread. Never do anything expensive in the main thread!

Also, try to minimize the area in which you get and set pixels. And, of course, if you already got the pixels, don't get them again (assuming they didn't change).

Also, if you do a lot of heavy lifting in your manipulation, you might want to consider JNI as a last resort. Really, really last resort.

EboMike
+2  A: 

I won't address performance (it may be fine to do the rendering in the main thread, or may not, depending on what you are doing). However if you need to get all touch data you should use MotionEvent.getHistoricalSize() and related methods to retrieve any intermediate movements that have happened from the last MotionEvent you processed to the current position in this MotionEvent.

hackbod