i have this code:
private Bitmap disk1, disk2, disk3;
private ArrayList<Bitmap> bitmapArray = new ArrayList<Bitmap>();
......
disk1 = BitmapFactory.decodeResource(getResources(), R.drawable.disk01);
disk1 = Bitmap.createBitmap(disk1, 0, 0, origW, origH, matrix, true);
disk2 = BitmapFactory.decodeResource(getResources(), R.drawable.disk02);
disk2 = Bitmap.createBitmap(disk2, 0, 0, origW, origH, matrix, true);
disk3 = BitmapFactory.decodeResource(getResources(), R.drawable.disk03);
disk3 = Bitmap.createBitmap(disk3, 0, 0, origW, origH, matrix, true);
bitmapArray.add(disk1);
bitmapArray.add(disk2);
bitmapArray.add(disk3);
i think to optimise code i can use this construction without bitmaps (with for loop):
bitmapArray.add(Bitmap.createBitmap(BitmapFactory.decodeResource(getResources(),
R.drawable.disk01), 0, 0, origW, origH, matrix, true));
but i’m little confused: it will store the result of methods or it will be call those methods every time when i try to get bitmapArray.get(0)?
thanx
update: i will use array after in handler callback to change animation on canvas:
Bitmap item;
.......
public Handler.Callback hc = new Handler.Callback() {
public boolean handleMessage(Message msg) {
switch (msg.what) {
case 1:
if (ai == 8)
ai = 0;
item = bitmapArray.get(ai);
++ai;
break;
maybe it is not call “optimization”, and I had to say “readability”
sorry for my bad english
get()just looks at a given position and returns whats there.add()just adds what was passed to it.There is no difference in
or
since the result of
is a Bitmap, regardles of saving it to an Bitmap object first or not.
It is like drinking from a bottle, you can fill it in a glas first, or drink directly from the bottle, in both cases you enjoy Cola or whatever.