Sunday, November 25, 2012

Re: [android-developers] canvas.drawBitmap draws over screen image instead of replacing screen image

Surfaces are double (or even triple) buffered. You are indeed not getting in your canvas what's currently on screen but what was on screen a frame ago. The easiest way to clear the surface is to call canvas.drawColor(0, PorterDuff.Mode.CLEAR) (you can also use 0xff000000, PorterDuff.Mode.SRC).


On Sun, Nov 25, 2012 at 3:42 PM, Johan <johan.wasserman@gmail.com> wrote:
I have some strange behaviour when repainting the screen with my live wallpaper.  I'm scaling an image and drawing it to the screen, but on each draw (as the image is scaled smaller than the previous draw), I can still see the previous image below the new image.
How do I clear the previous image out so that only the new scaled image is displayed?

This is my code:

private final Runnable mDraw = new Runnable() {
            public void run() {
                draw();
            }
        };

        void draw() {
        SurfaceHolder holder = getSurfaceHolder();
Canvas canvas = null;
try {
canvas = holder.lockCanvas();
if(canvas != null) {
this.paintScreen(canvas);
}
}finally {
if(canvas != null) {
holder.unlockCanvasAndPost(canvas);
}
}
mHandler.removeCallbacks(mDraw);
if (mVisible) {
mHandler.postDelayed(mDraw, 60000);
}
        }

Every minute my paintSurface function scales a bitmap (image loaded from resources), then uses canvas.drawBitmap to put the image on the screen.  As I understand from the documentation, holde.lockCanvas()is not supposed to contain the image currently on the screen and every pixel has to be drawn... this doesn't seem to be the case since the previous pixels are obviously under the new pixels.

Thanks,
J
(26 Sept '12 - 10:45 AM)

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en



--
Romain Guy
Android framework engineer
romainguy@android.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate