Używanie starszych wersji System.Drawing z IronOCR
.NET 4.6.1 do .NET 4.8 projekty zawierają wbudowaną wersję System.Drawing 4.0.0. Ta wersja System.Drawing nie jest już wspierana i może zawierać niebezpieczny kod.
Próba utworzenia OcrInput z System.Drawing.Image wywoła błąd "IronOcr.Exceptions.IronOcrProductException: 'Nie można zinterpretować Obiektu [] jako prawidłowego pliku obrazu.'". Dzieje się tak, ponieważ IronOcr nie mógł rozpoznać System.Drawing.Image jako prawidłowego typu wejściowego.

Próba określenia typu wejściowego Image jak OcrInput(Image: image) wywoła błąd "nie można przekonwertować z System.Drawing.Image na SixLabors.ImageSharp.Image".

Możliwe rozwiązania
-
Zaktualizuj System.Drawing.Common do wersji 6.0.0. Starsza wersja System.Drawing nie jest wspierana i może zawierać niebezpieczny kod.
- Użyj SixLabors.ImageSharp wersji 2.1.3.
OcrInputmożna utworzyć z typemSixLabors.ImageSharp.Image.
using IronOcr;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
class Program
{
static void Main()
{
var Ocr = new IronTesseract();
// Load the image using SixLabors.ImageSharp
Image image = Image.Load<Rgba32>("image.jpg");
// Use the image as input for OCR
using (var Input = new OcrInput(image))
{
// Perform OCR on the input
var Result = Ocr.Read(Input);
// Print the recognized text
Console.WriteLine(Result.Text);
}
}
}
using IronOcr;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
class Program
{
static void Main()
{
var Ocr = new IronTesseract();
// Load the image using SixLabors.ImageSharp
Image image = Image.Load<Rgba32>("image.jpg");
// Use the image as input for OCR
using (var Input = new OcrInput(image))
{
// Perform OCR on the input
var Result = Ocr.Read(Input);
// Print the recognized text
Console.WriteLine(Result.Text);
}
}
}
Imports IronOcr
Imports SixLabors.ImageSharp
Imports SixLabors.ImageSharp.PixelFormats
Friend Class Program
Shared Sub Main()
Dim Ocr = New IronTesseract()
' Load the image using SixLabors.ImageSharp
Dim image As Image = System.Drawing.Image.Load(Of Rgba32)("image.jpg")
' Use the image as input for OCR
Using Input = New OcrInput(image)
' Perform OCR on the input
Dim Result = Ocr.Read(Input)
' Print the recognized text
Console.WriteLine(Result.Text)
End Using
End Sub
End Class
- Powyższy kod inicjalizuje instancję
IronTesseract, ładuje obraz z pliku za pomocąSixLabors.ImageSharp, a następnie przetwarza obraz z IronOCR w celu wyodrębnienia tekstu.

