java - Why I obtain a black background when I create a new Bitmap in this way? How can I obtain a transparent backround? -


i pretty new in android development , have following problem.

i have implement code draw bitmap using canvas (it draw 5 icons 1 beside each other), code:

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      // retrieve imageview having id="star_container" (where put star.png image):     imageview myimageview = (imageview) findviewbyid(r.id.star_container);      // create bitmap image startin star.png "/res/drawable/" directory:     bitmap mybitmap = bitmapfactory.decoderesource(getresources(), r.drawable.star);      // create new image bitmap having width hold 5 star.png image:     bitmap tempbitmap = bitmap.createbitmap(mybitmap.getwidth() * 5, mybitmap.getheight(), bitmap.config.rgb_565);      /* attach brand new canvas new bitmap.        canvas class holds "draw" calls. draw something, need 4 basic components:        1) bitmap hold pixels.        2) canvas host draw calls (writing bitmap).        3) drawing primitive (e.g. rect, path, text, bitmap).        4) paint (to describe colors , styles drawing).      */     canvas tempcanvas = new canvas(tempbitmap);      // draw image bitmap cavas:     tempcanvas.drawbitmap(mybitmap, 0, 0, null);     tempcanvas.drawbitmap(mybitmap, mybitmap.getwidth(), 0, null);     tempcanvas.drawbitmap(mybitmap, mybitmap.getwidth() * 2, 0, null);     tempcanvas.drawbitmap(mybitmap, mybitmap.getwidth() * 3, 0, null);     tempcanvas.drawbitmap(mybitmap, mybitmap.getwidth() * 4, 0, null);      myimageview.setimagedrawable(new bitmapdrawable(getresources(), tempbitmap));  } 

so works fine , image correctly created , 5 star.png images showed, 1 beside each other).

the problem background of new image (behind star.png showed images) black. star.png image have white background.

i think depends line:

// create new image bitmap having width hold 5 star.png image: bitmap tempbitmap = bitmap.createbitmap(mybitmap.getwidth() * 5, mybitmap.getheight(), bitmap.config.rgb_565); 

in particolar bitmap.config.rgb_565.

what means?

how can change value obtain transparent background? (or @ least change color, example obtain white background)

in android documentation createbitmap find that:

android doc createbitmap

(for last argument) if config not support per-pixel alpha (e.g. rgb_565), alpha bytes in colors[] ignored (assumed ff)

so, instead use bitmap.config.argb_8888 last argument.

in configuration, each pixel stored on 4 bytes.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -