Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow encoding directly from frames #284

Closed
PazerOP opened this issue Jul 29, 2017 · 3 comments
Closed

Allow encoding directly from frames #284

PazerOP opened this issue Jul 29, 2017 · 3 comments

Comments

@PazerOP
Copy link

PazerOP commented Jul 29, 2017

It'd be nice to have IImageEncoder also have the overload

void Encode<TPixel>(ImageBase<TPixel> imageBase, Stream stream) where TPixel : struct, IPixel<TPixel>

That way, you can directly save frames of an image as separate images without having to clone them as you have to now:

var img = Image.Load(source);

foreach (var frame in img.Frames.Select((f, i) => (f, i)))
{
	var frameImg = new Image<Rgba32>(frame.Item1);

	var outputFile = File.Create($"frames/{frame.Item2}.png");
	frameImg.SaveAsPng(outputFile);
}
@JimBobSquarePants
Copy link
Member

JimBobSquarePants commented Oct 3, 2017

Your wish is granted! 😄

The latest builds on MyGet now allow exporting of frames

using( var img = Image.Load(source))
{
    foreach (var frame in img.Frames)
    {
        using (Image<TPixel> cloned = img.Frames.ExportFrame(i))
        {
         // Save cloned frame
        }
    }
}

@antonfirsov
Copy link
Member

@JimBobSquarePants what does .Select((f, i) => (f, i)) do in your sample code? Or is it just a typo?

@JimBobSquarePants
Copy link
Member

JimBobSquarePants commented Oct 3, 2017

I just copy/pasted the surrounding code above to be honest. It doesn't do anything now I look at it. I'll update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants