I have a drawing app where the user can draw on the screen with their finger. The drawing happens to an off-screen bitmap, and is then posted to the screen in onDraw().
When the user is switched away from the application, via a call or by hitting home, then returns to the app, the drawing screen is shown with the previous drawing, except the drawings edges now have artifacts. Cycling through a number of home -> resume -> home -> resume cycles results in the artifacts getting worse each time. See attached images for the results after five cycles.
Has anyone seen this before? Any idea why this is happening?
Thanks
Original drawing:
After 5 Cycles:
EDIT: More details:
As the user touches the screen, I intercept the touches and store them as Path's on an offscreen Bitmap, mBitmap. The Paths are drawn with a Paint that has the flag Paint.ANTI_ALIAS_FLAG enabled. The in onDraw(), I write them to the screen via:
@Override
protected void onDraw(Canvas canvas) {
// wipe the canvas
canvas.drawColor(0xffffffff);
// draw the stored paths
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
// draw any active paths
if (mStrokePath != null) {
canvas.drawPath(mStrokePath, mStrokePaint);
}
}
Where mBitmapPaint is defined as:
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
EDIT 2: Ok, got it figured out
My issue was that in the onResume for the Activity that creates the Canvas-based View, I was reloading the shapes onto the canvas ON TOP of the restored Bitmap, which already had the shapes, thus the deterioration of the anti-aliasing.