Skip to content

Allow encoding directly from frames #284

Closed

Description

@PazerOP

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);
}

Activity

  1. JimBobSquarePants commented on Oct 3, 2017

    @JimBobSquarePants
    Member

    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
            }
        }
    }
  2. antonfirsov commented on Oct 3, 2017

    @antonfirsov
    Member

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

  3. JimBobSquarePants commented on Oct 3, 2017

    @JimBobSquarePants
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions