开发者

How to Cut out RectF From a Bitmap?

开发者 https://www.devze.com 2023-03-31 05:20 出处:网络
I want to make a walking sprite anim开发者_StackOverflow中文版ation. I have a one bitmap with all 31 sprite frames. I draw one frame on canvas canvas.drawBitmap(bitmap, Rect src, RectF dst, paint). Th

I want to make a walking sprite anim开发者_StackOverflow中文版ation. I have a one bitmap with all 31 sprite frames. I draw one frame on canvas canvas.drawBitmap(bitmap, Rect src, RectF dst, paint). The problem is Rect src coordinates are int and when I divide bitmap.getWidth() by 31 to set a frame coordinates I get float. Is there a way to cut out RectF from a bitmap.

I can cut out Rect and scale it, but I would prefer the first option.


There is no way to cut out and store a piece of bitmap into memory with a float size. One can draw on float coordinates because it is possible to anti-alias the float edges on canvas.

So the solution I believe is to make your sprite sheet width = 31 x sprite_width, on the frist place, so that your cuts are a prefect match.

0

精彩评论

暂无评论...
验证码 换一张
取 消