@@ -133,7 +133,7 @@ private void generateDataFrom(final Frameset frameset, final UUID updateRequestI
133133 // Get the bounds where the frame is found
134134 final int [] bounds = frameset .getFrameBoundsAt (currentPosMs );
135135 generatedDataForUrl .put (currentPosMs ,
136- createBitmapSupplier (srcBitMap , bounds , frameset ));
136+ createBitmapSupplier (srcBitMap , bounds , frameset ));
137137
138138 currentPosMs += frameset .getDurationPerFrame ();
139139 pos ++;
@@ -168,6 +168,18 @@ private Supplier<Bitmap> createBitmapSupplier(final Bitmap srcBitMap,
168168 return null ;
169169 }
170170
171+ // Under some rare circumstances the YouTube API returns slightly too small storyboards,
172+ // (or not the matching frame width/height)
173+ // This would lead to createBitmap cutting out a bitmap that is out of bounds,
174+ // so we need to adjust the bounds accordingly
175+ if (srcBitMap .getWidth () < bounds [1 ] + frameset .getFrameWidth ()) {
176+ bounds [1 ] = srcBitMap .getWidth () - frameset .getFrameWidth ();
177+ }
178+
179+ if (srcBitMap .getHeight () < bounds [2 ] + frameset .getFrameHeight ()) {
180+ bounds [2 ] = srcBitMap .getHeight () - frameset .getFrameHeight ();
181+ }
182+
171183 // Cut out the corresponding bitmap form the "srcBitMap"
172184 final Bitmap cutOutBitmap = Bitmap .createBitmap (srcBitMap , bounds [1 ], bounds [2 ],
173185 frameset .getFrameWidth (), frameset .getFrameHeight ());
0 commit comments