Export pixel data from GIF frames

Hi Team!

I’m trying to load multi frame GIF images and get the pixel data (Argb32Pixels) from all the frames and having some issue with that.

I’m using the GifImage.Pages to access the image frames but there is a problem with that. When I save the frames to files the second frame contains some of the first frame pixels.

Is this the expected behavior?

I checked the documentation about exporting GIF frames to other image type. The export options has a FullFrame property and if I use it with true the problem is not occurs.

How can I access the frames without the “overlapping” pixels and without converting the frames into another image type?

I attached a .Net project so you can reproduce the issue.

GIF file: input.gif (118.0 KB)

GIF Original frames:
image.png (121.8 KB)

Extraction using Pages property:
image.png (124.5 KB)

Extraction after converting frames to BMP images:
image.png (127.9 KB)

Sample project: ExportGifFrames.zip (2.7 KB)

.Net Aspose.Imaging 24.3.0
OS Ubunut 20.04

Thank you for your help!

Hi, @erdeiga
Thank you for your interest in Aspose.Imaging.
Please, let me check your issue out.

1 Like

@erdeiga, Please use frame.GetFullFrame().LoadArgb32Pixels(frame.Bounds);

public void ExportFrames(bool save)
{
    using var image = Image.Load(path);
    var multipageImage = (IMultipageImage)image;
    for (int idx = 0; idx < multipageImage.PageCount; idx++)
    {
        var block = (multipageImage.Pages[idx] as GifFrameBlock);
        if (block == null)
        {
            continue;
        }

        using var fullFrame = block.GetFullFrame();
        var pixelData =  fullFrame.LoadArgb32Pixels(block.Bounds);
        var pixelDataByteCount = sizeof(int) * pixelData.Length;
        var tempBuffer = new byte[pixelDataByteCount];
        Buffer.BlockCopy(pixelData, 0, tempBuffer, 0, pixelDataByteCount);
        if (save)
        {
            SaveArgb32PixelsBufferToBmp(tempBuffer, block.Width, block.Height, $"frame_{idx}_from_Pages");
        }
    }
}

I noticed that you measure the execution time of some methods. Let me correct it a little.
On the first call, static classes are initialized, and the measurement of the first call is incorrect.
It is advisable to perform the first call without measurement, and then again with measurement.

           myImage.ExportFrames(saveOutput);
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            myImage.ExportFrames(saveOutput);
            stopwatch.Stop();
1 Like

@stanislav.popov Thank you for your help! It is working.