posted 10 years ago
Here are two suggestions:
1) Using a single off-screen Bitmap as a buffer to hold the drawing. Scale the off-screen buffer as needed for each activity
--- a - Create an empty Bitmap you will use as a drawing space (an off-screen copy of the drawing): drawingSpaceBitmap
--- b - Create a Canvas using the Bitmap to draw on (new Canvas(drawingSpaceBitmap))
--- c - Draw the background bitmap onto the canvas
--- d - On activity 1, draw drawingSpaceBitmap onto your ImageView
--- e - When user draws something, draw it using the Canvas, then trigger the ImageView to repaint. The image view should get the changes to the canvas via the drawingSpaceBitmap
--- f - On activity 2, add the drawingSpaceBitmap to your ImageButton and scale appropriately (maybe make a scaled copy if the image is static while this activity is visible to reduce the work needed to paint it). The button should get the results of the drawing on the canvas
2) Scale the drawings as you re-make them
--- a - Get the ratio of source image height to button height: scaleHeight
--- b - Get the ratio of source image width to button width: scaleWidth
--- c - Get the scaled image's width: scaledImageWidth
--- d - Get the button's width: buttonWidth
--- e - Get the X offset for drawing: (buttonWidth / 2) - (scaledImageWidth / 2) (+/- 1 pixel probably)
--- f - Get the Y offset for drawing: 0 (you said the image is drawing on the button's top to bottom.)
--- g - Draw objects with new positions.
--- --- - Positions are X:(offsetX + ( originalX * scaleWidth ) ) Y:( offsetY + ( originalY * scaleHeight ) )
--- --- - Sizes are Width:( originalWidth * scaleWidth ) Height:( originalHeight * scaleHeight )
--- --- - Horizontal lines are ( PositionXstart , PositionYstart ) -> ( ( PositionXstart + ( length * scaleWidth ) ) , PositionYstart )
--- --- - Vertical lines are ( PositionXstart , PositionYstart ) -> ( PositionXstart , ( PositionYstart + ( length * scaleHeight ) ) )
--- --- - Diagonal lines will require some extra math, but really just a combination of the X part of the Horizontal and Y part of the Vertical:
( PositionXstart , PositionYstart ) -> ( ( PositionXstart + ( originalDeltaX * scaleWidth ) ) , ( PositionYstart + ( originalDeltaY * scaleHeight ) ) )
Which should work if you know the original starting point and ending point. If you only know the lines starting point, angle, and length you will need to calculate the deltas.
All that math is why I lead with using an offscreen bitmap to draw and scale the results...