0
votes

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:

enter image description here

After 5 Cycles:

enter image description here

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.

3
could you give more details about how your bitmap display works? Are you saving over the same bitmap multiple times?Matthew Willis
I don't believe so... as the user draws, I write that data to an off-screen birmap, and then in onDraw(), canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); When the activity is restored, there is just a single call to onDraw that happens, nothing is being doen to change the offscrren bitmap.Unpossible

3 Answers

0
votes

I've never developed for Android before so I'm not familiar with its drawing system, but to me, your example looks like the original image has been drawn on top of itself multiple times, accentuating antialias edges. Have you any way of forcibly clearing/wiping the canvas and then redrawing when the user returns from the home screen?

0
votes

Consider using Paint.FILTER_BITMAP_FLAG.

0
votes

Per the EDIT 2 section in the posted question:

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.

So, not really an issue with the restored Canvas being an issue, rather the way I implemented loading the canvas was the issue. Going to mark this and close it.