日期:2014-05-20 浏览次数:20897 次
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
int images[][] = MainActivity.images;
int number = images.length;
int canvasWidth = canvas.getWidth();
int imageWidth = canvasWidth / number;
Bitmap bmp = BitmapFactory.decodeResource(getResources(), images[0][0]);
int srcWidth = bmp.getWidth();
float scale = (float) imageWidth / srcWidth;
if (!isStarted) {
canvas.drawColor(Color.WHITE);
for (int i = 0; i < number; i++) {
for (int j = 0; j < number; j++) {
Random rand = new Random();
Bitmap srcBmp = BitmapFactory.decodeResource(
getResources(), images[rand.nextInt(number)][0]);
Matrix matrix = new Matrix();
matrix.postScale(scale, scale);
Bitmap dstBmp = Bitmap
.createBitmap(srcBmp, 0, 0, srcBmp.getWidth(),
srcBmp.getHeight(), matrix, true);
canvas.drawBitmap(dstBmp, i * imageWidth, j * imageWidth,
null);
}
}
//isStarted = true; //加上的话就只执行一次,下次刷新图就都没了;不加的话每次都是全局刷新,相当于重新加载了
//我想要的效果是第一次完全加载,以后就是局部刷新。
}
else
{
if(isTouched)
{
}
}
}
Rect DrawRect = new Rect(srcPosition.x*imageWidth, srcPosition.y*imageWidth,
tarPosition.x*imageWidth, tarPosition.y*imageWidth);
touchView.invalidate(DrawRect);