|
1 | 1 | using SixLabors.ImageSharp; |
2 | 2 | using SixLabors.ImageSharp.Processing; |
3 | 3 | using System; |
| 4 | +using System.Collections.Generic; |
4 | 5 | using System.IO; |
| 6 | +using System.Linq; |
5 | 7 | using Xunit; |
6 | 8 | using Xunit.Abstractions; |
7 | 9 |
|
@@ -376,30 +378,88 @@ public void CastSixLabors_from_AnyBitmap() |
376 | 378 | public void Load_Tiff_Image() |
377 | 379 | { |
378 | 380 | AnyBitmap anyBitmap = AnyBitmap.FromFile(GetRelativeFilePath("IRON-274-39065.tif")); |
379 | | - Assert.Equal(1, anyBitmap.FrameCount); |
| 381 | + Assert.Equal(2, anyBitmap.FrameCount); |
380 | 382 |
|
381 | 383 | AnyBitmap multiPage = AnyBitmap.FromFile(GetRelativeFilePath("animated_qr.gif")); |
382 | 384 | Assert.Equal(4, multiPage.FrameCount); |
383 | | - Assert.Equal(4, multiPage.Frames.Count); |
384 | | - multiPage.Frames[0].SaveAs("first.png"); |
385 | | - multiPage.Frames[3].SaveAs("last.png"); |
| 385 | + Assert.Equal(4, multiPage.GetAllFrames.Count()); |
| 386 | + multiPage.GetAllFrames.First().SaveAs("first.png"); |
| 387 | + multiPage.GetAllFrames.Last().SaveAs("last.png"); |
386 | 388 | AssertImageAreEqual(GetRelativeFilePath("first-animated-qr.png"), "first.png"); |
387 | 389 | AssertImageAreEqual(GetRelativeFilePath("last-animated-qr.png"), "last.png"); |
388 | 390 |
|
389 | 391 | byte[] bytes = File.ReadAllBytes(GetRelativeFilePath("IRON-274-39065.tif")); |
390 | 392 | anyBitmap = AnyBitmap.FromBytes(bytes); |
391 | | - Assert.Equal(1, anyBitmap.FrameCount); |
| 393 | + Assert.Equal(2, anyBitmap.FrameCount); |
392 | 394 |
|
393 | 395 | byte[] multiPageBytes = File.ReadAllBytes(GetRelativeFilePath("animated_qr.gif")); |
394 | 396 | multiPage = AnyBitmap.FromBytes(multiPageBytes); |
395 | 397 | Assert.Equal(4, multiPage.FrameCount); |
396 | | - Assert.Equal(4, multiPage.Frames.Count); |
397 | | - multiPage.Frames[0].SaveAs("first.png"); |
398 | | - multiPage.Frames[3].SaveAs("last.png"); |
| 398 | + Assert.Equal(4, multiPage.GetAllFrames.Count()); |
| 399 | + multiPage.GetAllFrames.First().SaveAs("first.png"); |
| 400 | + multiPage.GetAllFrames.Last().SaveAs("last.png"); |
399 | 401 | AssertImageAreEqual(GetRelativeFilePath("first-animated-qr.png"), "first.png"); |
400 | 402 | AssertImageAreEqual(GetRelativeFilePath("last-animated-qr.png"), "last.png"); |
401 | 403 | } |
402 | 404 |
|
| 405 | + [FactWithAutomaticDisplayName] |
| 406 | + public void Try_UnLoad_Tiff_Image() |
| 407 | + { |
| 408 | + AnyBitmap anyBitmap = AnyBitmap.FromFile(GetRelativeFilePath("multiframe.tiff")); |
| 409 | + Assert.Equal(2, anyBitmap.FrameCount); |
| 410 | + } |
| 411 | + |
| 412 | + [FactWithAutomaticDisplayName] |
| 413 | + public void Create_Multi_page_Tiff() |
| 414 | + { |
| 415 | + List<AnyBitmap> bitmaps = new List<AnyBitmap>() |
| 416 | + { |
| 417 | + AnyBitmap.FromFile(GetRelativeFilePath("first-animated-qr.png")), |
| 418 | + AnyBitmap.FromFile(GetRelativeFilePath("last-animated-qr.png")) |
| 419 | + }; |
| 420 | + |
| 421 | + AnyBitmap anyBitmap = AnyBitmap.CreateMultiFrameTiff(bitmaps); |
| 422 | + Assert.Equal(2, anyBitmap.FrameCount); |
| 423 | + Assert.Equal(2, anyBitmap.GetAllFrames.Count()); |
| 424 | + anyBitmap.GetAllFrames.ElementAt(0).SaveAs("first.png"); |
| 425 | + anyBitmap.GetAllFrames.ElementAt(1).SaveAs("last.png"); |
| 426 | + AssertImageAreEqual(GetRelativeFilePath("first-animated-qr.png"), "first.png"); |
| 427 | + AssertImageAreEqual(GetRelativeFilePath("last-animated-qr.png"), "last.png"); |
| 428 | + } |
| 429 | + |
| 430 | + [FactWithAutomaticDisplayName] |
| 431 | + public void Create_Multi_page_Gif() |
| 432 | + { |
| 433 | + List<AnyBitmap> bitmaps = new List<AnyBitmap>() |
| 434 | + { |
| 435 | + AnyBitmap.FromFile(GetRelativeFilePath("first-animated-qr.png")), |
| 436 | + AnyBitmap.FromFile(GetRelativeFilePath("mountainclimbers.jpg")) |
| 437 | + }; |
| 438 | + |
| 439 | + AnyBitmap anyBitmap = AnyBitmap.CreateMultiFrameGif(bitmaps); |
| 440 | + Assert.Equal(2, anyBitmap.FrameCount); |
| 441 | + Assert.Equal(2, anyBitmap.GetAllFrames.Count()); |
| 442 | + anyBitmap.GetAllFrames.ElementAt(0).SaveAs("first.png"); |
| 443 | + Image first = Image.Load(GetRelativeFilePath("first-animated-qr.png")); |
| 444 | + first.Mutate(img => img.Resize(new ResizeOptions |
| 445 | + { |
| 446 | + Size = new SixLabors.ImageSharp.Size(anyBitmap.GetAllFrames.ElementAt(0).Width, anyBitmap.GetAllFrames.ElementAt(0).Height), |
| 447 | + Mode = SixLabors.ImageSharp.Processing.ResizeMode.BoxPad |
| 448 | + })); |
| 449 | + first.Save("first-expected.jpg"); |
| 450 | + AssertImageAreEqual("first-expected.jpg", "first.png", true); |
| 451 | + |
| 452 | + anyBitmap.GetAllFrames.ElementAt(1).SaveAs("last.png"); |
| 453 | + Image last = Image.Load(GetRelativeFilePath("mountainclimbers.jpg")); |
| 454 | + last.Mutate(img => img.Resize(new ResizeOptions |
| 455 | + { |
| 456 | + Size = new SixLabors.ImageSharp.Size(anyBitmap.GetAllFrames.ElementAt(1).Width, anyBitmap.GetAllFrames.ElementAt(1).Height), |
| 457 | + Mode = SixLabors.ImageSharp.Processing.ResizeMode.BoxPad |
| 458 | + })); |
| 459 | + last.Save("last-expected.jpg"); |
| 460 | + AssertImageAreEqual("last-expected.jpg", "last.png", true); |
| 461 | + } |
| 462 | + |
403 | 463 | #if !NET472 |
404 | 464 | [FactWithAutomaticDisplayName] |
405 | 465 | public void CastMaui_to_AnyBitmap() |
|
0 commit comments