I am making a drawing app, in which user can draw some basic shapes like square, triangle, line and free hand drawing.
I have created a custom view on which user can draw anything. When user select any shape, I am making new instance of custom view. And adding that view into root layout view.
After adding few shapes, app getting crash. As per the my observation, onSizeChanged() method making bitmap of device width and height. It might be a big bitmap if I am working on high resolution devices.
Quesion 1: Is it required to generate bitmap each time to draw on canvas?
Question 2: How to avoid and take care of out of memory issue?
`
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
super.onSizeChanged(w, h, oldw, oldh);
canvasBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
drawCanvas = new Canvas(canvasBitmap);
}
`
I have seen in many drawing example, they are making instance of bitmap and drawing it on canvas. Why is it required?
https://code.tutsplus.com/tutorials/android-sdk-create-a-drawing-app-touch-interaction--mobile-19202