1

I am implementing floodfill using Floodfill algorithm in Android and for paint operation we can implement undo redo with the path objects but how do we achieve this for floodfill operation without DrawingCache? Is there a way I can get Path object when I do the FloodFill operation?

Community
  • 1
  • 1
zek54
  • 415
  • 3
  • 20
  • The easiest way would be to save/cache hard-copies of the floodfill input (Bitmap image) or the underlying Bitmap model in a state-cache structure e.g. a serializable queue. If you want to have a undo-function for every step the floodfill algorithm does, you have to edit this algorithm... – Stilzk1n Jun 02 '16 at 11:38
  • Can you elaborate as to how can I change the algorithm as I want to be able to undo every step and not create multiple copies of bitmap. – zek54 Jun 02 '16 at 11:42
  • In the algorithm before: image.setPixel(x, y, replacement); you could safe a deep/hard copy of image in a Undo-Queue. This assumes, that you have to repeat the whole algorithm again, because the state (the current node) won't be saved this way... Except you have some event-listener on the Bitmap it won't update the canvas automatically on every setPixel anyway...? – Stilzk1n Jun 02 '16 at 11:51
  • Won't it give out of memory exception if I keep on saving the copy of bitmaps in a queue and don't undo for a while? – zek54 Jun 02 '16 at 11:56
  • Yes it would, that was just the basic idea... Apparently a Bitmap can be created out of those simple information? createBitmap(int[] colors, int width, int height, Bitmap.Config config) Returns a !!!immutable!!! bitmap with the specified width and height, with each pixel value set to the corresponding value in the colors array. So it would be okay to just save (in worst case serialize and save in file) those parts: int[] colors, int width, int height, Bitmap.Config config – Stilzk1n Jun 02 '16 at 12:08
  • How to get the colors[] of bitmap ? – zek54 Jun 02 '16 at 12:52
  • Regarding https://developer.android.com/reference/android/graphics/Bitmap.html with getPixels(int[] pixels, int offset, int stride, int x, int y, int width, int height) Returns in pixels[] a copy of the data in the bitmap. – Stilzk1n Jun 02 '16 at 13:32
  • ok, thanks for the help. – zek54 Jun 02 '16 at 17:38
  • @zek54 have you found solution? because I have same situation !!! – Harin Kaklotar Jan 11 '17 at 13:40

0 Answers0