1
我在java中爲android設備編寫了一個代碼,合併一些png圖像並創建一個位圖並在Imageview中顯示。它的工作原理,但之後,應用程序將太慢。我的代碼有什麼問題?我認爲這有點像內存泄漏!這樣對嗎?以及如何修復代碼?合併幾個圖像使android非常慢
public Drawable merge(Drawable a, String uri){
Drawable[] layers = new Drawable[2];
layers[0] = a;
int imageResource = getResources().getIdentifier(uri, null, getPackageName());
layers[1] = getResources().getDrawable(imageResource);
LayerDrawable layerDrawable = new LayerDrawable(layers);
return layerDrawable.mutate();
}
public void ShowImage(ArrayList<String> states) {
img1.setImageDrawable(null);
Drawable map = getResources().getDrawable(R.drawable.emptymap);
int i = 1;
for (String state : states) {
String layerName = state;
String uri = "drawable/"+layerName;
try {
map = merge(map ,uri);
}
catch(Exception e){}
}
img1.setImageDrawable(map);
}
提示:**從不**與空的catch塊。完全忽略錯誤是一個超級壞主意! – GhostCat