Reputation: 2372
I`m building an android App, and i got stuck with a simple thing: How do i draw (or "add") a Canvas object, to another Canvas object, like "merging" them?
If that`s not possible, what is the best solution for doing that?
Thanks!
Upvotes: 1
Views: 10205
Reputation: 67522
This depends entirely on your implementation.
If each Canvas draws objects directly from an array (of shapes, etc.) each frame, you could simply append one array to the other. This way, your Canvas does not need to be drastically altered, it only has to add one array to another (possibly an ArrayList
would be the way to go here).
If the above is not the case, you may have to make some more drastic changes. When I encountered a similar problem, I created a new method called commitChanges()
, which added a series of changes to an existing Canvas (adding lines on top, etc.).
Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGBA_8888);
.Canvas workingDrawing = new Canvas(bmp);
.canvas.drawBitmap(yourDrawnBitmap, 0.0f, 0.0f, null);
.I think the difficulty you'll face is transferring the data from one Canvas to another. But, regardless of your implementation, one of the above methods should work effectively for you.
Upvotes: 9