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
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