비트 맵을 찍고 원본에서 새 비트 맵을 만든 다음 새 비트 맵을 ImageView
으로 설정합니다. 원본을 재활용하면 원래대로 그려지는 것은 아닙니다. 자세한 내용은 내 코드에서 내 의견을 읽으십시오. 당신이 볼 수 있듯이 내가 그리지 않는 비트 맵을 재활용합니다. 항상 타일이라는 새로운 비트 맵을 만듭니다.왜 "재활용 비트 맵을 그릴 수 없습니까?"
내 코드 :
public void tileImage(Bitmap bm){
if(bm==null){
Debug.out("Bitmap is null");
}
else{
Bitmap tile;
float tileWidth = bm.getWidth();
float tileHeight =1024;
//if my bitmap is too wide
if(bm.getWidth()>width){
Debug.out("Bitmap too wide: "+bm.getWidth());
//if this code runs I get no error, if not I get the error
bm = Bitmap.createScaledBitmap(bm,
(int)width,
(int)(bm.getHeight()*(float)(width/tileWidth)),
false
);
}
Debug.out("Bitmap height: "+bm.getHeight()+" adjusted width "+bm.getWidth());
//if my bitmap is too tall
if(bm.getHeight()>tileHeight){
for(int i = 0; tileHeight*i<bm.getHeight(); i++){
image = new ImageView(main);
//make tiles of the body
if((tileHeight*(i+1))<bm.getHeight()){
tile = Bitmap.createBitmap(
bm,
0,
(int)(tileHeight*i),
(int)bm.getWidth(),
(int)(tileHeight)
);
Debug.out("Tiling: "+i);
}
//tile the reaminder
else{
tile = Bitmap.createBitmap(
bm,
0,
(int)(tileHeight*i),
(int)bm.getWidth(),
(int)(bm.getHeight()%tileHeight)
);
Debug.out("Tiling: "+bm.getHeight()%tileHeight+" "+i);
}
image.setImageBitmap(tile);
tiles.addView(image);
}
}
//else its not too tall
else{
image = new ImageView(main);
Debug.out("No tiling");
tile = Bitmap.createBitmap(
bm,
0,
0,
(int)bm.getWidth(),
(int)bm.getHeight()
);
Debug.out("Bitmap too small height: "+bm.getHeight()+" width "+bm.getWidth());
image.setImageBitmap(tile);
tiles.addView(image);
}
}
//this is the trouble maker
bm.recycle();
}
http://developer.android.com/training/displaying-bitmaps/manage-memory.html 참조하면 titleimage 방법의 호출 후에 비트 맵을 사용한 적이 – stinepike
없는 당신은 – Osman
입니다 ..하지만 경우에 표시되는 내용 비트 맵이 너무 넓을 때처럼 var을 재 할당하면 단서를 줘야합니다. 왜냐하면 블록이 오류를 발생시키지 않는 비트 맵에서 ... 동일한 비트 맵과 모든 것을 발생시키기 때문입니다. – stinepike