WinRT Convert JPG or PNG to GIF

I am working on a WinRT application that will do some image processing, and one of the things I want to do is convert jpg or png to gif. I have something like that. For some of my test jpgs, it works by others, it is a scrambled image that outputs the result. Just wondering if there is something that I have not seen. That's what i still have

public async static void ConvertToGif(IRandomAccessStream stream) { var decoder = await BitmapDecoder.CreateAsync(stream); var pixels = await decoder.GetPixelDataAsync(); var file = await KnownFolders.PicturesLibrary.CreateFileAsync("test.gif", CreationCollisionOption.ReplaceExisting); var outStream = await file.OpenAsync(FileAccessMode.ReadWrite); var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.GifEncoderId, outStream); encoder.SetPixelData(decoder.BitmapPixelFormat, BitmapAlphaMode.Ignore, decoder.PixelWidth, decoder.PixelHeight, decoder.DpiX, decoder.DpiY, pixels.DetachPixelData()); await encoder.FlushAsync(); outStream.Dispose(); } 

Smaller jpgs seem to work, but larger ones go beyond. Is there any other way to achieve this?

+4
source share
1 answer

I think the problem was that I used PixelWidth / Height, and I sholud used OrientedPixelWidth / Height.

I seem to have solved the problem for this.

+4
source

Source: https://habr.com/ru/post/1435793/


All Articles