有3个主要功能
drawImage:
private void drawImage(Canvas canvas) {
Bitmap image =
BitmapFactory.decodeResource(getResources(),
getResourceID("img_" + mIndex, "drawable", getApplicationContext()));
//Draw the image on screen
canvas.drawBitmap(image1, mPos.x, mPos.y, null);
}
drawFrame0:
private void drawFrame0() {
final SurfaceHolder SurfaceHolder = getSurfaceHolder();
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
Canvas canvas = null;
try {
canvas = SurfaceHolder.lockCanvas();
if (canvas != null) {
drawImage(canvas);/****draw layer 0*/
}
} finally {
if (canvas != null) {
SurfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
LiveWThread:
private class LiveWThread extends Thread {
private boolean continueRunning;
Engine engine;
public MoveBallsThread(Engine e) {
continueRunning = true ;
engine = e;
}
public void stopRunning() {
continueRunning = false ;
}
public void run() {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
try {
while (continueRunning) {
drawFrame0();
//incrementCounter22();
mIndex++;
...}
}
我的问题:无论如何我可以使用BitmapFactory.decodeResource只在应用程序启动时存储我的所有drawables而不使用Thread来循环它,因为每次Thread加载时,图像都必须再次解码,这显然减慢了我的动态壁纸上的图像流量.. 我将以jpg和png格式提供~100个drawables
非常感谢提前。