microsoft / Lumia-imaging-sdk

Lumia Imaging SDK is a comprehensive set of GPU/CPU imaging tools and effects that run on both mobile and desktop, with high speed and memory efficiency. Samples and extras code are included.
MIT License
75 stars 37 forks source link

GIF exporter: previous frames do not dispose on gifs with trnasparency #7

Open gritsenko opened 8 years ago

gritsenko commented 8 years ago

Hi! I'm trying to save animated gif composed from few bitmaps with transparency and it doesn't remove previous frame from animation. How can it be fixed?

Here is the result file:

pixels

My code: ` var outputFrames = new List(); for (inti = 0; i <= animationLength; i++) { CanvasRenderTarget offscreen = await Export(settings, vp, i);

                IBuffer buff = offscreen.GetPixelBytes().AsBuffer();

                SoftwareBitmap bm = SoftwareBitmap.CreateCopyFromBuffer(buff, BitmapPixelFormat.Bgra8, (int)offscreen.SizeInPixels.Width, (int)offscreen.SizeInPixels.Height);
                SoftwareBitmapImageSource bs = new SoftwareBitmapImageSource(bm);

                outputFrames.Add(bs);
            }

            using (var gifRenderer = new GifRenderer())
            {
                gifRenderer.Duration = 100;
                gifRenderer.NumberOfAnimationLoops = 10000;
                gifRenderer.UseGlobalPalette = false;
                gifRenderer.ApplyDithering = false;
                gifRenderer.Sources = outputFrames.ToArray();

                var buffer = await gifRenderer.RenderAsync();
                using (var stream = await fileToSave.OpenAsync(FileAccessMode.ReadWrite))
                {
                    await stream.WriteAsync(buffer);
                }
            }

`

davidbozjak commented 8 years ago

Hi,

Is it possible that you are using transparency in your frames? This is the result I would expect in case when you are only setting the pixels where your content (circle/ellipse in your case) appears, and leaving everything else unset - transparent.

You can either make sure that the API you are exporting the frames from has a background color, or you can blend in the background color with Lumia Imaging SDK before rendering.

gritsenko commented 8 years ago

Hi David! Yes I use transparency. When I don't everything is fine. But I need to save animation With transparency. So I asked if there is any way to dispose previous frames?

davidbozjak commented 8 years ago

No, not easily, that I'm aware off. I will investigate a bit and get back to you, but I think you will need to paint over the area in the previous frame with a background color, and then paint over your next frame.

I realize this is not ideal for your scenario...

gritsenko commented 8 years ago

In photoshop and Gimp there are option "dispose frame" like here: https://s3.amazonaws.com/satisfaction-production/s3_images/683741/disposal_inline.

and it allowed me to make: output_bezgs2

may be there is a way to erase area from previous frame with transparent color?