I’m using Aspose.Imaging within a linux container to convert PNG to grayscale which gives me the following exception/Stacktrace:
anzen_server | IndexWorker: Unexpected exception while indexing Document with Id ‘199411ca-46b1-4371-a504-6e7daee299bc’: System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform.
anzen_server | at System.Drawing.SystemFonts.get_DefaultFont()
anzen_server | at Aspose.Imaging.ImageOptionsBase…ctor()
anzen_server | at Aspose.Imaging.ImageOptions.PngOptions…ctor()
anzen_server | at Aspose.Imaging.FileFormats.Png.PngImage.SaveData(Stream stream)
anzen_server | at Aspose.Imaging.DataStreamSupporter.Save(Stream stream)
anzen_server | at appGenerics.Anzen.Infrastructure.Converters.AsposeHelper.ImageToGrayscale(Stream input) in /src/anzen_server/Infrastructure/Converters/AsposeHelper.cs:line 31
Seems that Linux is not fully supported here. What can I do?
Here comes the lines I use to convert the image:
using (Image image = Image.Load(input))
{
var tempFileName = Path.GetTempFileName();
try
{
using (var grayScaledStream = new FileStream(tempFileName, FileMode.Open, FileAccess.ReadWrite))
{
// Cast the image to RasterCachedImage and Check if image is cached
RasterCachedImage rasterCachedImage = (RasterCachedImage)image;
if (!rasterCachedImage.IsCached)
{
// Cache image if not already cached
rasterCachedImage.CacheData();
}
// Binarize image with predefined fixed threshold and Save the resultant image
rasterCachedImage.Grayscale();
rasterCachedImage.Save(grayScaledStream);
input.Position = 0;
grayScaledStream.CopyTo(input);
input.SetLength(grayScaledStream.Length);
}
}
finally
{
File.Delete(tempFileName);
}
Exception occurs in rasterCachedImage.Save(grayScaledStream);