android - Display an image in the form of an int array [] in an ImageView -


how display image in int [] format, example:

int[] um = {1,1,0,0,1,1,0,0,0,1,1,1,0,0,1,1,1,0,0,1,1,1,0,0,1,1,1,0,0,1,1,1,0,0,1,1,1,0,0,1,1,1,0,0,1}; 

here code:

public class mainactivity extends activity {      private imageview imageteste;     private bitmap bitmap;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         int[] um = {1,1,0,0,1,1,0,0,0,1,1,1,0,0,1,1,1,0,0,1,1,1,0,0,1,1,1,0,0,1,1,1,0,0,1,1,1,0,0,1,1,1,0,0,1};         bitmap = bitmap.createbitmap(um, 5, 9, bitmap.config.rgb_565);         imageteste = (imageview) findviewbyid(r.id.imageid);         imageteste.setimagebitmap(bitmap);     } } 

but not display anything, if change bitmap.config.argb_8888 parameter rgb_565, doing it, white pixels (1) turn black. converting values (1) 255 not work, displayed blue.

does know how solve problem?

the method you're using is: bitmap createbitmap (int[] colors, int width, int height, bitmap.config config). take @ documentation method here. int[] supply method must array of color ints. these not regular integers , using 0 or 1 these values making image appear empty.

check out android docs on color here.

for example, opaque blue 0xff0000ff. color ints have 4 components packed in single 32 bit integer value. 4 components represent alpha, red, green, , blue respectively. in example component ff meaning color opaque. r component 00, there's no red. g component 00, there's no green. b component ff, blue.

you'll need give createbitmap() method valid int[] , should solve problem.


Comments