0

I have a drawing application in Android that allows the user to draw with their finger, and then stores the resulting shapes as Android Paths. To allow the user to delete individual Paths 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

Community
  • 1
  • 1
Unpossible
  • 10,607
  • 22
  • 75
  • 113

1 Answers1

0

What is the actual representation of the "binary array"? I think if you tweak the representation to reflect the actual data you need to store (for example RLE encode the bits: at this y starting at this x and for z pixels) you will be able to store what you need to without excessive size.

Storing an actual array of bytes with one byte per pixel, or per 8 pixels (if that is what you are doing) isn't necessary for this use.

Another alternative is not to store a bitmap at all, just the control points and bounding boxes. If a touch intersects a bounding box, you calculate the bitmap on the fly from the control points.

antlersoft
  • 14,636
  • 4
  • 35
  • 55
  • The representation is that of a bitmap, so the array is of type int and has dimensions of rect_width, rect_height. Hmm, have thought about calculating the bitmap on the fly, but thought it might be too expensive from a performance point of view (although I might not have a choice, obviously). RLE might work too, so basically, I'd store the RLE instructions for the Path, and when trying to detect if point X,Y hits the Path, I'd then trace along the RLE? – Unpossible Jul 12 '11 at 20:47
  • @Paul -- You have a couple of options for RLE; one is for each y in the bounding box store the intersection of the path and that y as (x, run_length) objects (it's a bezier curve so there will be a maximum of two for each y, I guess...) – antlersoft Jul 12 '11 at 20:57