RemoveAllFrames

ApngImage.RemoveAllFrames method

Tar bort alla ramar från den egna ramsamlingen.

public void RemoveAllFrames()

Exempel

Följande exempel visar hur man skapar APNG-bild från en annan rasterbild på en sida.

[C#]

using Aspose.Imaging;
using Aspose.Imaging.ImageOptions;
using Aspose.Imaging.FileFormats.Apng;

const int AnimationDuration = 1000; // 1 s
const int FrameDuration = 70; // 70 ms
using (RasterImage sourceImage = (RasterImage)Image.Load("not_animated.png"))
{
    ApngOptions createOptions = new ApngOptions
    {
        Source = new FileCreateSource("raster_animation.png", false),
        DefaultFrameTime = (uint)FrameDuration,
        ColorType = PngColorType.TruecolorWithAlpha,
    };

    using (ApngImage apngImage = (ApngImage)Image.Create(
        createOptions,
        sourceImage.Width,
        sourceImage.Height))
    {
        // Det är möjligt att ställa in bildens standardbildtid där: apngImage.DefaultFrameTime = (uint)FrameDuration;

        int numOfFrames = AnimationDuration / FrameDuration;
        int numOfFrames2 = numOfFrames / 2;

        // Rengöring eftersom bilden innehåller en ram som standard
        apngImage.RemoveAllFrames();

        // lägg till första bildrutan
        apngImage.AddFrame(sourceImage);

        // lägg till mellanliggande ramar
        for (int frameIndex = 1; frameIndex < numOfFrames - 1; ++frameIndex)
        {
            apngImage.AddFrame(sourceImage);
            ApngFrame lastFrame = (ApngFrame)apngImage.Pages[apngImage.PageCount - 1];
            float gamma = frameIndex >= numOfFrames2 ? numOfFrames - frameIndex - 1 : frameIndex;
            lastFrame.AdjustGamma(gamma);
        }

        // lägg till sista bildrutan
        apngImage.AddFrame(sourceImage);

        apngImage.Save();
    }
}

Se även