duncan3052
duncan3052
CC#
Created by duncan3052 on 12/26/2022 in #help
❔ supporting .ico files on non-windows platforms
ah I sorted it, ico has no file type identifier at the beginning of the file so without the file suffix imagemagick cant identify what format it is in. The correct code is:
private static byte[] ConvertIcoToPng(byte[] bytes)
{
using MagickImage image = new (bytes, MagickFormat.Ico);
image.Format = MagickFormat.Png;
return image.ToByteArray();
}
private static byte[] ConvertIcoToPng(byte[] bytes)
{
using MagickImage image = new (bytes, MagickFormat.Ico);
image.Format = MagickFormat.Png;
return image.ToByteArray();
}
9 replies
CC#
Created by duncan3052 on 12/26/2022 in #help
❔ supporting .ico files on non-windows platforms
Thanks for the suggestion.
9 replies
CC#
Created by duncan3052 on 12/26/2022 in #help
❔ supporting .ico files on non-windows platforms
Its a pity I have to use a temp file, imagemagick can read a byte array but for some reason it fails in this case. Still this is a nicer and cleaner solution than any I found using the System.Drawing libs. I might use this lib (https://github.com/dlemstra/Magick.NET) for all my image needs in future.
9 replies
CC#
Created by duncan3052 on 12/26/2022 in #help
❔ supporting .ico files on non-windows platforms
private byte[] ConvertIcoToPng(byte[] bytes)
{
string tempFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".ico");
File.WriteAllBytes(tempFile, bytes);

using MagickImage image = new (tempFile);
image.Format = MagickFormat.Png;
File.Delete(tempFile);
return image.ToByteArray();
}
private byte[] ConvertIcoToPng(byte[] bytes)
{
string tempFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".ico");
File.WriteAllBytes(tempFile, bytes);

using MagickImage image = new (tempFile);
image.Format = MagickFormat.Png;
File.Delete(tempFile);
return image.ToByteArray();
}
9 replies
CC#
Created by duncan3052 on 12/26/2022 in #help
❔ supporting .ico files on non-windows platforms
looking at magick.net, I will post here if it works as a solution
9 replies