캐릭터 워킹 애니메이션의 프레임과 동일한 크기의 17 비트 맵을 가지고 있으며 코드에 루프를 넣길 원합니다. 나는 같은 비트 맵을 재사용하고 있기 때문에 inBitmap을 사용할 수 있기를 원한다. 그래서 어떻게하면Android java : 효율적인 비트 맵 애니메이션 할당
내가/I는 비트 맵을 캐시하고해야 할 수 있습니다 나는이 일에 대해 몇 가지 질문이?
더 효율적인 메모리 사용 방법은 무엇입니까?
내 코드는 다음과 같습니다 (나는 사용자 정의보기를 그릴 사용하고 있습니다)
에서 onCreate :
bitmapOptions.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), R.drawable.walk0, bitmapOptions);
aBitmap = Bitmap.createBitmap(bitmapOptions.outWidth,
bitmapOptions.outHeight, Bitmap.Config.ARGB_8888);
bitmapOptions.inJustDecodeBounds = false;
bitmapOptions.inBitmap = aBitmap;
bitmapOptions.inSampleSize = 1;
BitmapFactory.decodeResource(getResources(), R.drawable.walk0, bitmapOptions);
ship = Bitmap.createBitmap(aBitmap, 0, 0, aBitmap.getWidth(), aBitmap.getHeight(), shipMatrix, true);
된 onDraw :
@Override
protected void onDraw(Canvas canvas)
{
shipRectf.right = ship.getWidth();
shipRectf.left = 0;
shipRectf.top = 0;
shipRectf.bottom = ship.getHeight();
canvas.drawBitmap(ship, null, shipRectf, null);
}
에 애니메이션 :
Runnable walkData = new Runnable()
{
public void run(){
try{
BitmapFactory.Options shipOptions = null;
shipOptions = bitmapOptions;
if(shipOptions != null){
shipOptions.inBitmap = aBitmap;
}
if(walkAnim==true)
{
walkNum = (walkNum + 1) % imageIDs.length;
//walknum = index, imageids = int[] {R.drawables}
aBitmap = BitmapFactory.decodeResource(getResources(), imageIDs[walkNum], shipOptions);
ship = Bitmap.createBitmap(aBitmap, 0, 0, aBitmap.getWidth(), aBitmap.getHeight(), shipMatrix, true);
invalidate();
}
if(walkAnim==false)
{
walkNum = 0;
ship = BitmapFactory.decodeResource(getResources(), imageIDs[walkNum], shipOptions);
}
handler3.postDelayed(this, 50);
} catch (Exception e) {
e.printStackTrace();
}
}
};
애니메이션 드로어 블을 사용해 보셨습니까 ?? –
은 imageviews에 해당하지 않습니까? – stegrd
예 이미지 뷰 용 –