java - Android: Comparing images in a ImageButton and resource -
i have imagebutton , has background set this:
final imagebutton[][] gridbutton = new imagebutton[5][5]; gridbutton[0][0] = (imagebutton) findviewbyid(r.id.imagebutton1); gridbutton[0][0].setimageresource(buttonicon.l[0]); //buttonicon.l[0] image id resources folder. gridbutton[0][0].setonclicklistener(new view.onclicklistener() { buttonicon justanobject = new buttonicon(); @override public void onclick(view v) { int newid = justanobject.changeiconid(((bitmapdrawable)gridbutton[0][0].getdrawable()).getbitmap()); // int newid = justanobject.changeiconid(gridbutton[0][0].getdrawable()); gridbutton[0][0].setimageresource(newid); } }); in buttonicon class, have method making comparison:
public int changeiconid(bitmap object){ if (object == ((bitmapdrawable) getresources().getdrawable(r.drawable.load0)).getbitmap()){ return r.drawable.load1; } else return r.drawable.straight0; } all ids refer images in resources folder. i'm not quite sure how approach problem.
thanks.
to compare 2 bitmaps
public boolean equals(bitmap bitmap1, bitmap bitmap2) { bytebuffer buffer1 = bytebuffer.allocate(bitmap1.getheight() * bitmap1.getrowbytes()); bitmap1.copypixelstobuffer(buffer1); bytebuffer buffer2 = bytebuffer.allocate(bitmap2.getheight() * bitmap2.getrowbytes()); bitmap2.copypixelstobuffer(buffer2); return arrays.equals(buffer1.array(), buffer2.array()); } *after update *
comparing 2 drawables
bitmap bitmap = ((bitmapdrawable)fdraw).getbitmap(); bitmap bitmap2 = ((bitmapdrawable)sdraw).getbitmap(); if(bitmap == bitmap2) { //code blcok }
Comments
Post a Comment