Android - Background Image Animation In Loop
I'm trying to animate an image (used as background image but it doesn't really matter) in such a way that it will move from left to right but in a cyclic way. For example, if the i
Solution 1:
If the Bitmap
and the ImageView
are the exact same size in pixels you can manually move the pixels around however you want.
int pixels[];
bitmap.getPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
shiftPixels(pixels, width, height);
bitmap.setPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.setWidth());
In shiftPixels
simply create a copy of the original bitmap but when copying the pixels apply a linear shift to the pixels. Something like this (un-tested pseudo-code);
voidshiftPixels(int inPixels[], int bitmapHeight, int nPixHorizShift)
{
intshift= bitmapHeight * nPixHorizShift;
int outPixels[inPixels.size()];
fori=1:pixels.size()
outPixels[(i + shift) % outPixels.size()] = inPixels[i];
inPixels = outPixels;
}
Post a Comment for "Android - Background Image Animation In Loop"