I have a drawing application in Android that allows the user to draw with their finger, and then stores the resulting shapes as Android Path
s. To allow the user to delete individual Path
s they have drawn, I have implemented this solution that uses a bounding Rect
for each Path
, and then uses an inner multi-dimensional binary array to represent the pixels inside the bounding Rect
. I then populate the array by taking the Path's control points and track along it using the mathematical equation for a quadratic bezier curve, setting each element in the array that would have a pixel underneath it to 1.
Using the above setup, when in erasing mode, I first check for collision between the users finger and the bounding Rect
, and if that collides, I then check to see if the pixel being touched by the user is set to a 1 in the array.
Now, when a user loads a note, I load all of the shapes into an ArrayList
of 'stroke' objects so that I can then easily display them and can loop through them checking for collision when in erase mode. I also store the Rect
and binary array with the strokes in the custom object. Everything is working as expected, but the memory footprint of storing all of this data, specifically the binary array for each Path's bounding Rect
, is getting expensive, and when a user has a large number of strokes I am getting a java.lang.OutOfMemoryError
on the portion of my code that is creating the array for each stroke.
Any suggestions on a better way to accomplish this? Essentially, I am trying to determine collision between two Android Paths (the drawing Path, and then a Path that the user creates when in erase mode), and while the above works in theory, in practice it is not feasible.
Thanks,
Paul