EPPlus工作表.Drawings.AddPicture()不支持docker上的Jpg/Png



我目前正在编写一个程序,该程序生成条形码,然后将其保存为具有标准文件扩展名(例如jpeg、png(的本地图像。之后,我需要使用工作表将生成的条形码图像导入到新创建的excel文件中。Drawings.AddPicture((方法。当我将程序作为控制台应用程序运行时,一切都正常,但当我使用Docker运行程序时,会引发以下异常:

System.InvalidOperationException: No image handler for image type Jpg
at OfficeOpenXml.Drawing.PictureStore.GetImageBounds(Byte[] image, ePictureType type, ExcelPackage pck)
at OfficeOpenXml.Drawing.PictureStore.AddImage(Byte[] image, Uri uri, Nullable`1 pictureType)
at OfficeOpenXml.Drawing.ExcelPicture.SaveImageToPackage(ePictureType type, Byte[] img)
at OfficeOpenXml.Drawing.ExcelPicture.LoadImage(Stream stream, ePictureType type)
at OfficeOpenXml.Drawing.ExcelDrawings.AddPicture(String Name, FileInfo ImageFile, Uri Hyperlink)
at OfficeOpenXml.Drawing.ExcelDrawings.AddPicture(String Name, FileInfo ImageFile)

对于条形码生成,我使用ZXing.Net版本0.16.8。对于图像生成,我使用ImageSharp 2.1.3版(因为,据我所知,标准的System.Drawing.Common库仅在Windows上受支持(

string temporaryBarcodeImagePath = $"barcode.jpeg";
var barcodeMatrix = _barcodeManager.GenerateCode128(order.ReferenceNumber, 400, 20);
await _barcodeManager.SaveBarcodeImageAsync(temporaryBarcodeImagePath, barcodeMatrix);
var picture = worksheet.Drawings.AddPicture("Barcode", temporaryBarcodeImagePath);
picture.SetPosition(20, 20);

_barcodeManager只是一个在文件系统中本地生成并保存条形码图像的服务。我不认为这个问题与此有关。

到目前为止,我发现的唯一类似问题是以下github问题:https://github.com/EPPlusSoftware/EPPlus/issues/645

然而,在这个问题中,有问题的错误是在EPPlus 6.0.5版本中修复的,这正是我目前使用的版本。

如有任何帮助,我们将不胜感激。提前感谢!

我在以下github问题线程中提供了一些解释:

https://github.com/EPPlusSoftware/EPPlus/issues/645

最新更新