android - Draw bitmaps from resources over another -


i have got 2 bitmaps, background , foreground. how draw bitmap foreground on background without using canvas?

solution:

1) first create bitmaps resources additional option argb_8888

bitmapfactory.options options = new bitmapfactory.options();   options.inpreferredconfig = bitmap.config.argb_8888; 

2) declare bitmaps

bitmap background = bitmapfactory.decoderesource(getresources(), r.drawable.background, options);   bitmap foreground = bitmapfactory.decoderesource(getresources(), r.drawable.foreground, options); 

3) inside ondraw() function draw graphics

protected void ondraw(canvas canvas)     {       canvas.drawcolor(color.white);      paint paint = new paint();     canvas.drawbitmap(background, 0, 0, paint);     paint.setxfermode( new porterduffxfermode(porterduff.mode.src_over));     canvas.drawbitmap(foreground, 0, 0, paint);  } 

and soxxeh said, source of information: http://developer.android.com/resources/samples/apidemos/src/com/example/android/apis/graphics/xfermodes.html

try this:

canvas.drawbitmap(backgroundimagebitmap, 0.0f, 0.0f, null); canvas.drawbitmap(foregroundimagebitmap, 0.0f, 0.0f, null); 

the second image (foreground image) has have alpha aspects or can't see through it.


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -