我编写了一个用Java调整数组大小的方法:
public HUD resize(float factor){
int[] array = new int[(int)Math.pow(pixels.length * factor, 2)];//Create new array
for(int y = 0; y < height; ++y){
for(int x = 0; x < width; ++x){
array[(int)((x * 2) + (y * 2) * width * factor)] = pixels[x + y * width];
array[(int)((x * 2 + 1) + (y * 2) * width * factor)] = pixels[x + y * width];
array[(int)((x * 2) + (y * 2 + 1) * width * factor)] = pixels[x + y * width];
array[(int)((x * 2 + 1) + (y * 2 + 1) * width * factor)] = pixels[x + y * width];
}
}
pixels = array;
width = (int)(width * factor);
height = (int)(height * factor);
return this;
}
此方法仅调用一次,并且只要调用
,就会发出OutOfMemoryError