Utilisation d'anciennes versions de System.Drawing avec IronOCR
Les projets .NET 4.6.1 à .NET 4.8 intègrent une version 4.0.0 de System.Drawing. Cette version de System.Drawing n'est plus prise en charge et peut contenir du code vulnérable.
La tentative d'instanciation d'OcrInput à partir de System.Drawing.Image générera l'erreur suivante : « IronOcr.Exceptions.IronOcrProductException : 'Impossible d'analyser l'objet [] comme un fichier image valide.' ». C'est parce qu'IronOCR n'a pas pu reconnaître System.Drawing.Image comme un type d'entrée valide.

Essayer de spécifier le type d'entrée image comme OcrInput(Image: image) produira une erreur "impossible de convertir de System.Drawing.Image à SixLabors.ImageSharp.Image".

Solutions possibles
-
Mettez à jour System.Drawing.Common vers une version actuelle et prise en charge. La version plus ancienne de System.Drawing n'est plus supportée et peut contenir du code vulnérable.
-
Chargez l'image avec
OcrInput.LoadImage, qui accepte un chemin de fichier,byte[],Stream, ouIronSoftware.Drawing.AnyBitmap. Dans la version actuelle de IronOCR,OcrInputa un constructeur sans paramètres et gère le chargement des images en interne, vous n'avez donc pas besoin de SixLabors.ImageSharp ou System.Drawing pour préparer l'entrée.using IronOcr; class Program { static void Main() { var Ocr = new IronTesseract(); // Load the image directly with IronOCR using (var Input = new OcrInput()) { Input.LoadImage("image.jpg"); // Perform OCR on the input var Result = Ocr.Read(Input); // Print the recognized text Console.WriteLine(Result.Text); } } }Imports IronOcr Class Program Shared Sub Main() Dim Ocr = New IronTesseract() ' Load the image directly with IronOCR Using Input = New OcrInput() Input.LoadImage("image.jpg") ' Perform OCR on the input Dim Result = Ocr.Read(Input) ' Print the recognized text Console.WriteLine(Result.Text) End Using End Sub End ClassImports IronOcr Class Program Shared Sub Main() Dim Ocr = New IronTesseract() ' Load the image directly with IronOCR Using Input = New OcrInput() Input.LoadImage("image.jpg") ' Perform OCR on the input Dim Result = Ocr.Read(Input) ' Print the recognized text Console.WriteLine(Result.Text) End Using End Sub End Class -
Le code ci-dessus initialise une instance de
IronTesseract, charge une image à partir d'un fichier avecOcrInput.LoadImage, puis traite l'image avec IronOCR pour extraire du texte.
Curtis Chau détient un baccalauréat en informatique (Université de Carleton) et se spécialise dans le développement front-end avec expertise en Node.js, TypeScript, JavaScript et React. Passionné par la création d'interfaces utilisateur intuitives et esthétiquement plaisantes, Curtis aime travailler avec des frameworks modernes et créer des manuels bien structurés et visuellement attrayants.