@@ -52,25 +52,32 @@ private static Bitmap superimposedFrame(LottieComposition lottieComposition) {
52
52
}
53
53
54
54
private static Bitmap blackFrame (Bitmap superimposedFrame ) {
55
- int [] pixels = new int [ superimposedFrame .getWidth () * superimposedFrame .getHeight ()] ;
56
- int [] pixelsBlack = new int [ superimposedFrame . getWidth () * superimposedFrame . getHeight ()] ;
55
+ Bitmap bigFrame = Bitmap . createBitmap ( superimposedFrame .getWidth () * 4 , superimposedFrame .getHeight () * 4 , Bitmap . Config . ARGB_8888 ) ;
56
+ Canvas bigCanvas = new Canvas ( bigFrame ) ;
57
57
58
- Bitmap frame = Bitmap .createBitmap (superimposedFrame .getWidth (), superimposedFrame .getHeight (), Bitmap .Config .ARGB_8888 );
58
+ Paint paint = new Paint ();
59
+ paint .setFilterBitmap (true );
60
+ paint .setDither (true );
61
+ paint .setAntiAlias (true );
62
+ bigCanvas .drawBitmap (superimposedFrame , new Rect (0 , 0 , superimposedFrame .getWidth (), superimposedFrame .getHeight ()), new Rect (0 , 0 , bigFrame .getWidth (), bigFrame .getHeight ()), paint );
63
+
64
+ int [] pixels = new int [bigFrame .getWidth () * bigFrame .getHeight ()];
65
+ int [] pixelsBlack = new int [bigFrame .getWidth () * bigFrame .getHeight ()];
59
66
60
- superimposedFrame .getPixels (pixels , 0 , superimposedFrame .getWidth (), 0 , 0 , superimposedFrame .getWidth (), superimposedFrame .getHeight ());
61
- for (int y = 0 ; y < superimposedFrame .getHeight (); y ++) {
67
+ bigFrame .getPixels (pixels , 0 , bigFrame .getWidth (), 0 , 0 , bigFrame .getWidth (), bigFrame .getHeight ());
68
+ for (int y = 0 ; y < bigFrame .getHeight (); y ++) {
62
69
int last = 0 ;
63
70
boolean inside = false ;
64
71
int start = -1 ;
65
72
int end = -1 ;
66
73
67
- int index = y * superimposedFrame .getWidth ();
68
- for (int x = 0 ; x < superimposedFrame .getWidth (); x ++) {
74
+ int index = y * bigFrame .getWidth ();
75
+ for (int x = 0 ; x < bigFrame .getWidth (); x ++) {
69
76
int p = pixels [index ];
70
- if ((p == 0 ) && (last != 0 )) {
77
+ if ((p != 0xFFFFFFFF ) && (last == 0xFFFFFFFF )) {
71
78
start = x ;
72
79
inside = true ;
73
- } else if (inside && (p != 0 ) && (last == 0 )) {
80
+ } else if (inside && (p == 0xFFFFFFFF ) && (last != 0xFFFFFFFF )) {
74
81
end = x ;
75
82
break ;
76
83
}
@@ -79,15 +86,24 @@ private static Bitmap blackFrame(Bitmap superimposedFrame) {
79
86
}
80
87
81
88
if ((start >= 0 ) && (end >= 0 ) && (end >= start )) {
82
- index = y * superimposedFrame .getWidth ();
89
+ index = y * bigFrame .getWidth ();
83
90
for (int x = start ; x < end ; x ++) {
84
91
pixelsBlack [index + x ] = (int )0xFF000000 ;
85
92
}
86
93
}
87
94
}
88
- frame .setPixels (pixelsBlack , 0 , superimposedFrame .getWidth (), 0 , 0 , superimposedFrame .getWidth (), superimposedFrame .getHeight ());
89
95
90
- return frame ;
96
+ Bitmap bigBlackFrame = Bitmap .createBitmap (bigFrame .getWidth (), bigFrame .getHeight (), Bitmap .Config .ARGB_8888 );
97
+ bigBlackFrame .setPixels (pixelsBlack , 0 , bigFrame .getWidth (), 0 , 0 , bigFrame .getWidth (), bigFrame .getHeight ());
98
+
99
+ Bitmap blackFrame = Bitmap .createBitmap (superimposedFrame .getWidth (), superimposedFrame .getHeight (), Bitmap .Config .ARGB_8888 );
100
+ Canvas blackCanvas = new Canvas (blackFrame );
101
+ blackCanvas .drawBitmap (bigBlackFrame , new Rect (0 , 0 , bigBlackFrame .getWidth (), bigBlackFrame .getHeight ()), new Rect (0 , 0 , blackFrame .getWidth (), blackFrame .getHeight ()), paint );
102
+
103
+ bigFrame .recycle ();
104
+ bigBlackFrame .recycle ();
105
+
106
+ return blackFrame ;
91
107
}
92
108
93
109
public static SpriteSheet fromLottieComposition (LottieComposition lottieComposition , int width , int height , SpritePlayer .Mode mode ) {
0 commit comments