コード例 #1
0
        //当场生成Gif
        async Task playUgoira()
        {
            try
            {
                using (GifRenderer renderer = new GifRenderer())
                {
                    renderer.Duration = ugoira.Frames[0].Delay;
                    renderer.Size     = new Size(ugoira.Frames[0].Image.PixelWidth, ugoira.Frames[0].Image.PixelHeight);
                    List <IImageProvider> sources = new List <IImageProvider>();
                    foreach (var i in ugoira.Frames)
                    {
                        sources.Add(new SoftwareBitmapImageSource(i.Image));
                    }
                    renderer.Sources = sources;
                    buffer           = await renderer.RenderAsync();
                }
                var gif = new BitmapImage();
                await gif.SetSourceAsync(buffer.AsStream().AsRandomAccessStream());

                ugoiraPlayer.Source = gif;
            }
            finally
            {
                ugoira.Dispose();
            }
        }
コード例 #2
0
        public static async Task Export(IReadOnlyList<IImageProvider> images, Rect? animatedArea)
        {
            ImageProviderInfo info = await images[0].GetInfoAsync();
            int w = (int)info.ImageSize.Width;
            int h = (int)info.ImageSize.Height;

            IReadOnlyList<IImageProvider> gifRendererSources;
            if (animatedArea.HasValue)
            {
                gifRendererSources = CreateFramedAnimation(images, animatedArea.Value, w, h);
            }
            else
            {
                gifRendererSources = images;
            }

            using (GifRenderer gifRenderer = new GifRenderer())
            {
                gifRenderer.Duration = 100;
                gifRenderer.NumberOfAnimationLoops = 10000;
                gifRenderer.Sources = gifRendererSources;

                var buffer = await gifRenderer.RenderAsync();

                var filename = "ImageSequencer." + (await GetFileNameRunningNumber()) + ".gif";
                var storageFile = await KnownFolders.PicturesLibrary.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
                using (var stream = await storageFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    await stream.WriteAsync(buffer);
                }
            }
        }
コード例 #3
0
        public static async Task <BitmapImage> CreateGifBitmapImageAsync(bool isBranded, List <IImageProvider> images, ObservableCollection <Emoji> ResultsEmojis)
        {
            BitmapImage bitmap;
            IBuffer     buffer;

            double scaleForTwitter = 0.5;

            //get size of gif based on saved images
            var height = ResultsEmojis[0].BestPicWB.PixelHeight * scaleForTwitter;
            var width  = ResultsEmojis[0].BestPicWB.PixelWidth * scaleForTwitter;

            using (var gifRenderer = new GifRenderer(images))
            {
                gifRenderer.Size     = new Size(width, height);
                gifRenderer.Duration = 100;
                buffer = await gifRenderer.RenderAsync();
            }

            bitmap = new BitmapImage();
            await bitmap.SetSourceAsync(buffer.AsStream().AsRandomAccessStream());

            if (isBranded)
            {
                ResultsPage.GifStream = buffer.AsStream();
            }

            return(bitmap);
        }
コード例 #4
0
        public static async Task Export(IReadOnlyList <IImageProvider> images, Rect?animatedArea)
        {
            ImageProviderInfo info = await images[0].GetInfoAsync();
            int w = (int)info.ImageSize.Width;
            int h = (int)info.ImageSize.Height;

            IReadOnlyList <IImageProvider> gifRendererSources;

            if (animatedArea.HasValue)
            {
                gifRendererSources = CreateFramedAnimation(images, animatedArea.Value, w, h);
            }
            else
            {
                gifRendererSources = images;
            }

            using (GifRenderer gifRenderer = new GifRenderer())
            {
                gifRenderer.Duration = 100;
                gifRenderer.NumberOfAnimationLoops = 10000;
                gifRenderer.Sources = gifRendererSources;

                var buffer = await gifRenderer.RenderAsync();

                var filename    = "ImageSequencer." + (await GetFileNameRunningNumber()) + ".gif";
                var storageFile = await KnownFolders.PicturesLibrary.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);

                using (var stream = await storageFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    await stream.WriteAsync(buffer);
                }
            }
        }
コード例 #5
0
        public static async Task Export(IReadOnlyList<IImageProvider> images, Rect? animatedArea)
        {
            // List of aligned images may contain Null items if the particular image couldn't be aligned
            List<IImageProvider> sanitizedImages = new List<IImageProvider>();
            foreach (IImageProvider image in images) {
                if (image != null) {
                    sanitizedImages.Add(image);
                }
            }

            IImageResource info = null;
            IAsyncImageResource asyncImageResource = sanitizedImages[0] as IAsyncImageResource;
            if (asyncImageResource == null)
            {
                info = sanitizedImages[0] as IImageResource;
            }
         
            int w = (int)info.ImageSize.Width;
            int h = (int)info.ImageSize.Height;

            IReadOnlyList<IImageProvider> gifRendererSources;
            if (animatedArea.HasValue)
            {
                // Ensure the animated area dimensions are smaller than the image dimensions
                double rectW = animatedArea.Value.Width;
                double rectH = animatedArea.Value.Height;
                if ((animatedArea.Value.Width + animatedArea.Value.Left) >= w)
                {
                    rectW = w - animatedArea.Value.Left - 1;
                }
                if ((animatedArea.Value.Top + animatedArea.Value.Height) >= h)
                {
                    rectH = h - animatedArea.Value.Top - 1;
                }

                Rect rect = new Rect(animatedArea.Value.Left, animatedArea.Value.Top, rectW, rectH);
                gifRendererSources = CreateFramedAnimation(sanitizedImages, rect, w, h);
            }
            else
            {
                gifRendererSources = sanitizedImages;
            }

            using (GifRenderer gifRenderer = new GifRenderer())
            {
                gifRenderer.Duration = 100;
                gifRenderer.NumberOfAnimationLoops = 10000;
                gifRenderer.Sources = gifRendererSources;

                var buffer = await gifRenderer.RenderAsync();

                var filename = "Sequence" + (await GetFileNameRunningNumber()) + ".gif";
                var storageFile = await KnownFolders.SavedPictures.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
                using (var stream = await storageFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    await stream.WriteAsync(buffer);
                }
            }
        }
コード例 #6
0
        public static async Task Export(IReadOnlyList <IImageProvider> images, Rect?animatedArea)
        {
            // List of aligned images may contain Null items if the particular image couldn't be aligned
            List <IImageProvider> sanitizedImages = new List <IImageProvider>();

            foreach (IImageProvider image in images)
            {
                if (image != null)
                {
                    sanitizedImages.Add(image);
                }
            }

            ImageProviderInfo info = await sanitizedImages[0].GetInfoAsync();
            int w = (int)info.ImageSize.Width;
            int h = (int)info.ImageSize.Height;

            IReadOnlyList <IImageProvider> gifRendererSources;

            if (animatedArea.HasValue)
            {
                // Ensure the animated area dimensions are smaller than the image dimensions
                double rectW = animatedArea.Value.Width;
                double rectH = animatedArea.Value.Height;
                if ((animatedArea.Value.Width + animatedArea.Value.Left) >= w)
                {
                    rectW = w - animatedArea.Value.Left - 1;
                }
                if ((animatedArea.Value.Top + animatedArea.Value.Height) >= h)
                {
                    rectH = h - animatedArea.Value.Top - 1;
                }

                Rect rect = new Rect(animatedArea.Value.Left, animatedArea.Value.Top, rectW, rectH);
                gifRendererSources = CreateFramedAnimation(sanitizedImages, rect, w, h);
            }
            else
            {
                gifRendererSources = sanitizedImages;
            }

            using (GifRenderer gifRenderer = new GifRenderer())
            {
                gifRenderer.Duration = 100;
                gifRenderer.NumberOfAnimationLoops = 10000;
                gifRenderer.Sources = gifRendererSources;

                var buffer = await gifRenderer.RenderAsync();

                var filename    = "Sequence" + (await GetFileNameRunningNumber()) + ".gif";
                var storageFile = await KnownFolders.SavedPictures.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);

                using (var stream = await storageFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    await stream.WriteAsync(buffer);
                }
            }
        }
コード例 #7
0
ファイル: MainPage.xaml.cs プロジェクト: taberon/PhotoBooth
        async void MakeGif()
        {
            List <IImageProvider> imageSourceList = new List <IImageProvider>();

            // add image sources to define sequence of GIF frames
            for (int i = 0; i < this.bitmapFrames.Length; ++i)
            {
                SoftwareBitmap softwareBitmap = this.bitmapFrames[i];
                if (softwareBitmap != null)
                {
                    SoftwareBitmapImageSource imageSource = new SoftwareBitmapImageSource(softwareBitmap);
                    imageSourceList.Add(imageSource);
                }
            }

            // use lumia imaging SDK component to create animated GIF image
            GifRenderer gifRenderer = new GifRenderer(imageSourceList);

            gifRenderer.Duration = 100;               // time for each frame in ms
            gifRenderer.NumberOfAnimationLoops = 200; // loop continuosly
            gifRenderer.ApplyDithering         = false;

            Windows.Storage.Streams.IBuffer gifBuffer = await gifRenderer.RenderAsync();


            // show animated gif in xaml preview area
            BitmapImage animBitmap = new BitmapImage();
            await animBitmap.SetSourceAsync(gifBuffer.AsStream().AsRandomAccessStream());

            // set preview animated gif
            this.imageAnimPreview.Source = animBitmap;

            bool saveImage = false;

            if (saveImage)
            {
                // write animated gif image to file
                string timeString = DateTime.Now.ToString("yyyyMMdd-HHmm_ss");
                string filename   = $"PhotoBooth_{timeString}.gif";
                Windows.Storage.StorageFile storageFile = await Windows.Storage.KnownFolders.SavedPictures.CreateFileAsync(filename, Windows.Storage.CreationCollisionOption.ReplaceExisting);

                using (var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite))
                {
                    await stream.WriteAsync(gifBuffer);
                }
            }
        }
コード例 #8
0
        public static async Task Export(IReadOnlyList <IImageProvider> images, Rect?animatedArea)
        {
            ImageProviderInfo info = await images[0].GetInfoAsync();
            int w = (int)info.ImageSize.Width;
            int h = (int)info.ImageSize.Height;

            IReadOnlyList <IImageProvider> gifRendererSources;

            if (animatedArea.HasValue)
            {
                gifRendererSources = CreateFramedAnimation(images, animatedArea.Value, w, h);
            }
            else
            {
                gifRendererSources = images;
            }

            using (GifRenderer gifRenderer = new GifRenderer())
            {
                gifRenderer.Size     = new Windows.Foundation.Size(w, h);
                gifRenderer.Duration = 100;
                gifRenderer.NumberOfAnimationLoops = 10000;
                gifRenderer.Sources = gifRendererSources;

                var buffer = await gifRenderer.RenderAsync();

                using (IsolatedStorageFileStream file = IsolatedStorageFile.GetUserStoreForApplication().CreateFile("exported." + GetFileNameRunningNumber() + ".gif"))
                {
                    Stream bufferStream = buffer.AsStream();
                    bufferStream.CopyTo(file);
                    bufferStream.Close();
                    bufferStream.Dispose();
                    file.Flush();
                }
            }
        }
コード例 #9
0
        public static async Task Export(IReadOnlyList<IImageProvider> images, Rect? animatedArea)
        {
            ImageProviderInfo info = await images[0].GetInfoAsync();
            int w = (int)info.ImageSize.Width;
            int h = (int)info.ImageSize.Height;

            IReadOnlyList<IImageProvider> gifRendererSources;
            if (animatedArea.HasValue)
            {
                gifRendererSources = CreateFramedAnimation(images, animatedArea.Value, w, h);
            }
            else
            {
                gifRendererSources = images;
            }

            using (GifRenderer gifRenderer = new GifRenderer())
            {
                gifRenderer.Size = new Windows.Foundation.Size(w, h);
                gifRenderer.Duration = 100;
                gifRenderer.NumberOfAnimationLoops = 10000;
                gifRenderer.Sources = gifRendererSources;

                var buffer = await gifRenderer.RenderAsync();

                using (IsolatedStorageFileStream file = IsolatedStorageFile.GetUserStoreForApplication().CreateFile("exported." + GetFileNameRunningNumber() + ".gif"))
                {
                    Stream bufferStream = buffer.AsStream();
                    bufferStream.CopyTo(file);
                    bufferStream.Close();
                    bufferStream.Dispose();
                    file.Flush();
                }

            }
        }
コード例 #10
0
        }//hide progress bar

        private async Task SaveImagesAsGifFileAsync(WriteableBitmap[] imageArray)
        {
            try
            {
                //convert images from imageArray to IBuffer (to save it as GIF-file then)
                GC.Collect();
                List <IImageProvider> imageProviders = new List <IImageProvider>();
                for (int i = 0; i < imageArray.Length; i++)
                {
                    var buffFrame    = imageArray[i];
                    var buffBitmap   = buffFrame.AsBitmap();
                    var bufferSource = new BitmapImageSource(buffBitmap);
                    imageProviders.Add(bufferSource);
                }
                GC.Collect();
                GifRenderer gifRenderer = new GifRenderer();
                gifRenderer.Duration = rate;
                gifRenderer.NumberOfAnimationLoops = 10000;
                gifRenderer.UseGlobalPalette       = false;
                gifRenderer.Sources = imageProviders;
                await Task.Delay(TimeSpan.FromSeconds(1));

                Windows.Storage.Streams.IBuffer buff = await gifRenderer.RenderAsync();

                //crete/open folder
                StorageFolder folder;
                try { folder = await KnownFolders.PicturesLibrary.GetFolderAsync("GIF Editor"); }
                catch (Exception)
                {
                    folder = await KnownFolders.PicturesLibrary.CreateFolderAsync("GIF Editor");
                }

                //generate next unique name
                ulong num = 0;
                do
                {
                    num++;
                    filename = num + ".gif";
                } while (await folder.FileExists(filename));

                //save file
                var storageFile = await folder.CreateFileAsync(filename, CreationCollisionOption.GenerateUniqueName);

                using (var memoryStream = await storageFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    await Task.Delay(TimeSpan.FromSeconds(1));

                    await memoryStream.WriteAsync(buff);
                }
                gifRenderer.Dispose();
                imageProviders = null;
                GC.Collect();
            }
            catch (OutOfMemoryException)
            {
                var dlg = new MessageDialog(Localize("memoryError"));
                await dlg.ShowAsync();
            }
            catch (Exception)
            {
                Frame.Navigate(typeof(MainPage));
            }
        }//convert images to GIF-file and save it
コード例 #11
0
        public static async Task Export(IReadOnlyList <IImageProvider> images, Rect?animatedArea, int Duration)
        {
            int Count = 0;
            ImageProviderInfo infoImageOne = await images[0].GetInfoAsync();
            // Getting Height and Width of First picked image as a reference point
            int w1 = (int)infoImageOne.ImageSize.Width;
            int h1 = (int)infoImageOne.ImageSize.Height;
            IReadOnlyList <IImageProvider> gifRendererSources;

            for (int i = 1; i < images.Count; i++)
            {
                ImageProviderInfo infoImageTwo = await images[i].GetInfoAsync();
                int w2 = (int)infoImageTwo.ImageSize.Width;
                int h2 = (int)infoImageTwo.ImageSize.Height;

                if (w1 != w2 && h1 != h2)
                {
                    Count++;
                }
            }
            if (Count == 1 || Count > 1)
            {
                MessageBox.Show("Please Select Images of Same Dimensions");
            }
            else
            {
                gifRendererSources = images;



                //if (animatedArea.HasValue)
                //{
                // //    gifRendererSources = CreateFramedAnimation(images, animatedArea.Value, w, h);
                //}
                //else
                //{
                //      gifRendererSources = images;
                //}

                using (GifRenderer gifRenderer = new GifRenderer())
                {
                    try {
                        gifRenderer.Duration = Duration;
                        gifRenderer.NumberOfAnimationLoops = 100;
                        gifRenderer.Sources = gifRendererSources;

                        var buffer = await gifRenderer.RenderAsync();

                        var filename    = "GifCreator." + (await GetFileNameRunningNumber()) + ".gif";
                        var storageFile = await KnownFolders.PicturesLibrary.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);

                        using (var stream = await storageFile.OpenAsync(FileAccessMode.ReadWrite))
                        {
                            await stream.WriteAsync(buffer);
                        }
                    }
                    catch (Exception ex) {
                        MessageBox.Show(ex.ToString());
                    }
                }

                MessageBox.Show("Gif has been saved successfully in Gallery.");
            }
        }