@@ -282,16 +282,15 @@ public static Image getBmpImage(byte[] bytes, boolean noHeader, int size) {
282
282
}
283
283
284
284
/**
285
- * Return a GifImage object. This object cannot be
285
+ * Return a GifImage object. This object cannot be added to a document
286
286
* @param bytes
287
287
* @return
288
288
*/
289
289
public static GifImage getGifImage (byte [] bytes ) {
290
290
byte [] imageType = readImageType (bytes );
291
291
if (imageTypeIs (imageType , gif )) {
292
292
GifImage image = new GifImage (bytes );
293
- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
294
- GifImageHelper .processImage (image , baos );
293
+ GifImageHelper .processImage (image );
295
294
return image ;
296
295
}
297
296
throw new IllegalArgumentException ("GIF image expected." );
@@ -307,8 +306,7 @@ public static Image getGifFrame(URL url, int frame) {
307
306
byte [] imageType = readImageType (url );
308
307
if (imageTypeIs (imageType , gif )) {
309
308
GifImage image = new GifImage (url );
310
- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
311
- GifImageHelper .processImage (image , baos , frame - 1 );
309
+ GifImageHelper .processImage (image , frame - 1 );
312
310
return image .getFrames ().get (frame - 1 );
313
311
}
314
312
throw new IllegalArgumentException ("GIF image expected." );
@@ -324,8 +322,7 @@ public static Image getGifFrame(byte[] bytes, int frame) {
324
322
byte [] imageType = readImageType (bytes );
325
323
if (imageTypeIs (imageType , gif )) {
326
324
GifImage image = new GifImage (bytes );
327
- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
328
- GifImageHelper .processImage (image , baos , frame - 1 );
325
+ GifImageHelper .processImage (image , frame - 1 );
329
326
return image .getFrames ().get (frame - 1 );
330
327
}
331
328
throw new IllegalArgumentException ("GIF image expected." );
@@ -341,9 +338,8 @@ public static List<Image> getGifFrames(byte[] bytes, int[] frameNumbers) {
341
338
byte [] imageType = readImageType (bytes );
342
339
if (imageTypeIs (imageType , gif )) {
343
340
GifImage image = new GifImage (bytes );
344
- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
345
341
Arrays .sort (frameNumbers );
346
- GifImageHelper .processImage (image , baos , frameNumbers [frameNumbers .length - 1 ] - 1 );
342
+ GifImageHelper .processImage (image , frameNumbers [frameNumbers .length - 1 ] - 1 );
347
343
List <Image > frames = new ArrayList <>();
348
344
for (int frame : frameNumbers ) {
349
345
frames .add (image .getFrames ().get (frame - 1 ));
@@ -363,9 +359,8 @@ public static List<Image> getGifFrames(URL url, int[] frameNumbers) {
363
359
byte [] imageType = readImageType (url );
364
360
if (imageTypeIs (imageType , gif )) {
365
361
GifImage image = new GifImage (url );
366
- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
367
362
Arrays .sort (frameNumbers );
368
- GifImageHelper .processImage (image , baos , frameNumbers [frameNumbers .length - 1 ] - 1 );
363
+ GifImageHelper .processImage (image , frameNumbers [frameNumbers .length - 1 ] - 1 );
369
364
List <Image > frames = new ArrayList <>();
370
365
for (int frame : frameNumbers ) {
371
366
frames .add (image .getFrames ().get (frame - 1 ));
@@ -375,6 +370,36 @@ public static List<Image> getGifFrames(URL url, int[] frameNumbers) {
375
370
throw new IllegalArgumentException ("GIF image expected." );
376
371
}
377
372
373
+ /**
374
+ * Returns <CODE>List</CODE> of gif image frames
375
+ * @param bytes byte array of gif image
376
+ * @return all frames of gif image
377
+ */
378
+ public static List <Image > getGifFrames (byte [] bytes ) {
379
+ byte [] imageType = readImageType (bytes );
380
+ if (imageTypeIs (imageType , gif )) {
381
+ GifImage image = new GifImage (bytes );
382
+ GifImageHelper .processImage (image );
383
+ return image .getFrames ();
384
+ }
385
+ throw new IllegalArgumentException ("GIF image expected." );
386
+ }
387
+
388
+ /**
389
+ * Returns <CODE>List</CODE> of gif image frames
390
+ * @param url url of gif image
391
+ * @return all frames of gif image
392
+ */
393
+ public static List <Image > getGifFrames (URL url ) {
394
+ byte [] imageType = readImageType (url );
395
+ if (imageTypeIs (imageType , gif )) {
396
+ GifImage image = new GifImage (url );
397
+ GifImageHelper .processImage (image );
398
+ return image .getFrames ();
399
+ }
400
+ throw new IllegalArgumentException ("GIF image expected." );
401
+ }
402
+
378
403
public static Image getJbig2Image (URL url , int page ) {
379
404
if (page < 1 )
380
405
throw new IllegalArgumentException ("The page number must be greater than 0" );
@@ -508,8 +533,7 @@ private static Image getImageInstance(URL source, boolean recoverImage) {
508
533
byte [] imageType = readImageType (source );
509
534
if (imageTypeIs (imageType , gif )) {
510
535
GifImage image = new GifImage (source );
511
- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
512
- GifImageHelper .processImage (image , baos , 0 );
536
+ GifImageHelper .processImage (image , 0 );
513
537
return image .getFrames ().get (0 );
514
538
} else if (imageTypeIs (imageType , jpeg )) {
515
539
Image image = new JpegImage (source );
@@ -553,8 +577,7 @@ private static Image getImageInstance(byte[] bytes, boolean recoverImage) {
553
577
byte [] imageType = readImageType (bytes );
554
578
if (imageTypeIs (imageType , gif )) {
555
579
GifImage image = new GifImage (bytes );
556
- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
557
- GifImageHelper .processImage (image , baos , 0 );
580
+ GifImageHelper .processImage (image , 0 );
558
581
return image .getFrames ().get (0 );
559
582
} else if (imageTypeIs (imageType , jpeg )) {
560
583
Image image = new JpegImage (bytes );
0 commit comments