MagickImage.Read() should raise an exception when specifying an invalid FrameIndex
See original GitHub issueFirst, thanks for maintaining this - it’s great!
Prerequisites
- I have written a descriptive issue title
- I have verified that I am using the latest version of Magick.NET
- I have searched open and closed issues to ensure it has not already been reported
Description
When trying to read a specific frame past the last frame from e.g. a PDF, a MagicImage
is disposed, and
No pages will be processed (FirstPage > LastPage).
is written on stdout.
Instead, I think an exception should be raised so that this situation can be dealt with in a nicer way than the sample below.
var magickReadSettings = new MagickReadSettings {FrameIndex = 42};
using (MagickImage mi = new MagickImage())
{
try
{
mi.Read("onePagePdf.pdf", magickReadSettings);
// after reading, mi is _disposed_ if we have read past end. Try to access a field to
// see if this is the case (and if it is, catch the exception)
var dummy = mi.Width;
}
catch (System.ObjectDisposedException)
{
Console.WriteLine("read past the last frame.");
}
}
An additional nice-to-have would be a fast way of determining the number of pages in a PDF without having to load the whole thing 😃
System Configuration
ios, linux.
- Magick.NET version: 7.22.2.2
- Environment (Operating system, version and so on): seen on mac, dockerized ubuntu
- Additional information:
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
c# - ImageMagick.NET - Faster performance
You can specify the page you want to read with the FrameIndex ... If you specify a page that is too high an...
Read more >Magick.NET
ImageMagick is a powerful image manipulation library that supports over 100 major file formats (not including sub-formats). With Magick.NET you can use ...
Read more >C# (CSharp) ImageMagick MagickImage.Read Examples
Description: The MagickImage Read method is part of the ImageMagick library in C# and is used to read and decode images from a...
Read more >C# (CSharp) ImageMagick MagickReadSettings Examples
Class that contains setting for when an image is being read. ... FrameIndex = 1; settings. ... public void Test_Constructor() { ExceptionAssert.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is it possible to reproduce the issue in GitHub actions?
p.s. Getting a fast page count will become available in the next release.
We made some changes in the PDF reading, can you give it another try with the latest release @martinkoch-geniebelt? And I would advise you to use the new
PdfInfo
class to get the page count.