1. Check out our app, Forums for Android! Download and leave feedback here!

Problem with transparency in Live Wallpaper

Discussion in 'Application Development' started by itooriziu, Dec 4, 2010.

  1. itooriziu

    itooriziu New Member
    Thread Starter
    5

    Dec 4, 2010
    2
    0
    5
    I need to draw a bitmap of a Basketball over other bitmap.
    the problem is that (from my understandings) bitmaps doesn't support transparcy, and the background behind the ball is white color.

    I tried to use setPixel(x,y,color.transparant) on the white pixels, but when
    i send it to draw, it draws black pixels (the color of the android background) instead of transparant pixels.

    here is what i try to do:

    these are the two bitmaps:
    backgroundBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.grass1);
    ballBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ball1);


    ..
    ..
    ..
    ..


    void drawWallpaper()
    {
    final SurfaceHolder sh = getSurfaceHolder();

    Canvas canvas = new Canvas();
    try
    {

    canvas = sh.lockCanvas();
    if (canvas != null)
    {
    drawB(canvas);
    }
    }

    finally
    {
    if (canvas != null)
    {
    sh.unlockCanvasAndPost(canvas);
    }
    }

    handler.removeCallbacks(runnable);
    if (visible == true)
    {
    handler.postDelayed(runnable, 200);
    }

    }

    void drawB(Canvas canvas)
    {

    xBall = surfaceRect.right / 2;
    yBall = surfaceRect.bottom / 2;
    canvas.drawBitmap(backgroundBitmap, null, surfaceRect, paint);
    canvas.drawBitmap(ballBitmap, xBall, yBall, paint);

    }


    as i said, it draws the ball while the background behind is black (instead of transparat - in order to see the backgroundBitmap below)

    what should i do?

    thanks
     

    Advertisement

  2. itooriziu

    itooriziu New Member
    Thread Starter
    5

    Dec 4, 2010
    2
    0
    5
    i just found out i can load a png file into Bitmap.
    which means:
    ballBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ball1); is also working while "ball1" is a png file.

    thanks me :)
     

Share This Page

Loading...