0
我想畫一個精靈表動畫在屏幕上,當我使用此代碼這個工作的罰款之前的部分圖像。創建的其他圖像
canvas.drawColor(Color.TRANSPARENT);
Rect src = new Rect(CurrentSprite.x * SheetSize.x, CurrentSprite.y * SheetSize.y, (CurrentSprite.x * SheetSize.x) + SheetSize.x, (CurrentSprite.y * SheetSize.y) + SheetSize.y);
Rect dst = new Rect(X, Y, X + SheetSize.x, Y + SheetSize.y);
canvas.drawBitmap(bmp, src, dst, null);
但是我現在需要旋轉圖像,然後才能在屏幕上繪製圖像。所以我更改了代碼,以便製作精靈的本地副本。我要畫這個但是在這裏我遇到了一個問題。我使用的是Bitmap.createBitmap方法,但似乎這種方法不執行任何操作,因爲當我看着屏幕上的完整的精靈表是在屏幕上繪製,有時我得到OutOfMemoryException異常(理解的,因爲完整的圖像是相當大的)。
canvas.drawColor(Color.TRANSPARENT);
Matrix matrix = new Matrix();
matrix.postRotate(Degrees);
Bitmap tempAnimationBmp = Bitmap.createBitmap(bmp, CurrentSprite.x * SheetSize.x, CurrentSprite.y * SheetSize.y, (CurrentSprite.x * SheetSize.x) + SheetSize.x, (CurrentSprite.y * SheetSize.y) + SheetSize.y, matrix, true);
canvas.drawBitmap(tempAnimationBmp, X, Y, null);
tempAnimationBmp.recycle();
爲什麼我會得到完整的精靈表?
看看我在這篇文章中的答案。我認爲你可以改變它到你的要求:http://stackoverflow.com/questions/12330220/androiddraw-image-in-the-center-of-another-image/12332941#12332941 –