Drawing mirrored bitmaps in android

前端 未结 3 1114
一个人的身影
一个人的身影 2020-12-03 03:12

I\'m trying to learn how to make an animated sprite in android and couldn\'t figure out how to go about organising my bitmaps. I have a sprite sheet of my character walking

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 03:35

    Method 2 would be way too expensive, and you don't need a canvas to flip a bitmap. Simply create another bitmap with a Matrix applied, like so:

    BitmapDrawable flip(BitmapDrawable d)
    {
        Matrix m = new Matrix();
        m.preScale(-1, 1);
        Bitmap src = d.getBitmap();
        Bitmap dst = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), m, false);
        dst.setDensity(DisplayMetrics.DENSITY_DEFAULT);
        return new BitmapDrawable(dst);
    }
    

提交回复
热议问题