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!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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
ArrayListwould 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.