-
I'm having trouble converting a stream from a private static Stream GetAPngStreamAsync(Stream gifStream)
{
using var imageCollection = new MagickImageCollection(gifStream, MagickFormat.Gif);
var result = new MemoryStream();
imageCollection.Write(result, MagickFormat.APng);
return result;
} Then I get the resulting stream and save it to a file using using var processedStream = GetAPngStreamAsync(stream);
var buffer = new byte[processedStream.Length];
processedStream.Write(buffer);
await File.WriteAllBytesAsync("/home/user/Pictures/sample.png", buffer); However, this always generates an invalid file that no image handling program can open. But if I write to a file directly from imageCollection.Write("/home/user/Pictures/sample.png", MagickFormat.APng); Then I get a perfectly functional file. For my purposes though, I really need a valid stream and I'd like to avoid an I/O operation to write a new file, then read back from it. Also, this is unrelated, but how can I accelerate/slow down the animation in the resulting |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You will need to reset the position of the stream? You might also be worth to consider using |
Beta Was this translation helpful? Give feedback.
You will need to reset the position of the stream? You might also be worth to consider using
imageCollection.ToByteArray(MagickFormat.APng)
instead when you want to change the image into a byte array?