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); } } }
public async void SetImageSequence(List <IImageProvider> imageProviders) { ShowProgressIndicator("Aligning frames"); SetControlsEnabled(false); _unalignedImageProviders = imageProviders; _onScreenImageProviders = _unalignedImageProviders; // Create aligned images using (ImageAligner imageAligner = new ImageAligner()) { imageAligner.Sources = _unalignedImageProviders; imageAligner.ReferenceSource = _unalignedImageProviders[0]; _alignedImageProviders = await imageAligner.AlignAsync(); } // Create on-screen bitmap for rendering the image providers IImageProvider imageProvider = _onScreenImageProviders[0]; ImageProviderInfo info = await imageProvider.GetInfoAsync(); int width = (int)info.ImageSize.Width; int height = (int)info.ImageSize.Height; _foregroundImage = new WriteableBitmap(width, height); _backgroundImage = new WriteableBitmap(width, height); // Render the first frame of sequence await Render(0, true); InitializeAnimatedAreaBasedOnImageDimensions(width, height); SetControlsEnabled(true); HideProgressIndicator(); }
public async Task PrepareImageSequence(List <IImageProvider> imageProviders) { _unalignedImageProviders = imageProviders; _onScreenImageProviders = _unalignedImageProviders; ImageProviderInfo info = await _unalignedImageProviders[0].GetInfoAsync(); _unalignedImageWidth = (int)info.ImageSize.Width; _unalignedImageHeight = (int)info.ImageSize.Height; using (ImageAligner imageAligner = new ImageAligner()) { imageAligner.Sources = _unalignedImageProviders; imageAligner.ReferenceSource = _unalignedImageProviders[0]; try { _alignedImageProviders = await imageAligner.AlignAsync(); info = await _alignedImageProviders[0].GetInfoAsync(); _alignedImageWidth = (int)info.ImageSize.Width; _alignedImageHeight = (int)info.ImageSize.Height; await EnableAlign(); } catch (Exception) { // If align fails, fail silently but don't enable the align button on UI } } }
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); } } }
private void EndSession() { if (_source != null) { _source.Dispose(); _source = null; } _info = null; }
private void BeginSession(Stream image) { // Initialize session with image using (var memoryStream = new MemoryStream()) { image.Position = 0; image.CopyTo(memoryStream); try { // Some streams do not support flushing image.Flush(); } catch (Exception) { } memoryStream.Position = 0; // Initialize image source _source = new StreamImageSource(memoryStream); // Get image info Task.Run(async() => { _info = await _source.GetInfoAsync(); }).Wait(); // Set _lowResolutionBitmap decoding to a quite low resolution and initialize it with image if (_info.ImageSize.Width >= _info.ImageSize.Height) { _bitmap.DecodePixelWidth = 1536; _bitmap.DecodePixelHeight = 0; } else { _bitmap.DecodePixelWidth = 0; _bitmap.DecodePixelHeight = 1536; } image.Position = 0; _bitmap.SetSource(image); } }
private void EndSession() { if (_renderer != null) { _renderer.Dispose(); _renderer = null; } if (_filterEffect != null) { _filterEffect.Dispose(); _filterEffect = null; } if (_source != null) { _source.Dispose(); _source = null; } _reframingFilter = null; _info = null; }
private IImageProvider Crop(BitmapImageSource overlayBitmapImageSource, ImageProviderInfo originalOverlayImageProviderInfo, int backgroundWidth, int backgroundHeight) { IImageProvider imageProvider; int overlayWidth = (int)overlayBitmapImageSource.Bitmap.Dimensions.Width; int overlayHeight = (int)overlayBitmapImageSource.Bitmap.Dimensions.Height; if (HorizontalAlignment != HorizontalAlignment.None) { int cropLeft = 0; int cropTop = 0; int cropWidth = Math.Min(overlayWidth, (int)originalOverlayImageProviderInfo.ImageSize.Width); int cropHeight = Math.Min(overlayHeight, (int)originalOverlayImageProviderInfo.ImageSize.Height); if ((HorizontalAlignment == HorizontalAlignment.Center) && (overlayWidth < (int)originalOverlayImageProviderInfo.ImageSize.Width)) { cropLeft = Math.Abs(overlayWidth / 2 - backgroundWidth / 2); cropWidth -= cropLeft * 2; } if ((VerticalAlignment == HorizontalAlignment.Center) && (overlayHeight < (int)originalOverlayImageProviderInfo.ImageSize.Height)) { cropTop = Math.Abs(overlayHeight / 2 - backgroundHeight / 2); cropHeight -= cropTop * 2; } imageProvider = new CropEffect(new Rect(cropLeft, cropTop, cropWidth, cropHeight)); } else { imageProvider = overlayBitmapImageSource; } return(imageProvider); }
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(); } } }
private void BeginSession(Stream image) { System.Diagnostics.Debug.WriteLine("Begin session"); // Initialize session with image using (var memoryStream = new MemoryStream()) { image.Position = 0; image.CopyTo(memoryStream); try { // Some streams do not support flushing image.Flush(); } catch (Exception) { } memoryStream.Position = 0; // Initialize image source _source = new StreamImageSource(memoryStream); // Get image info Task.Run(async() => { _info = await _source.GetInfoAsync(); }).Wait(); // Create crop filter effect _reframingFilter = new ReframingFilter(); _filterEffect = new FilterEffect(_source) { Filters = new List <IFilter>() { _reframingFilter } }; // Create renderer _renderer = new WriteableBitmapRenderer(_filterEffect, _highResolutionCropBitmap); } // Set _lowResolutionBitmap decoding to a quite low resolution and initialize it with image if (_info.ImageSize.Width >= _info.ImageSize.Height) { _lowResolutionBitmap.DecodePixelWidth = 1536; _lowResolutionBitmap.DecodePixelHeight = 0; } else { _lowResolutionBitmap.DecodePixelWidth = 0; _lowResolutionBitmap.DecodePixelHeight = 1536; } image.Position = 0; _lowResolutionBitmap.SetSource(image); // Set LowResolutionCropBrush scaling so that it matches with the pixel perfect HighResolutionCropImage renderings var screenScaleFactor = App.Current.Host.Content.ScaleFactor / 100.0; var lowResolutionToHighResolutionCropScale = _info.ImageSize.Width / _lowResolutionBitmap.PixelWidth / screenScaleFactor * DIGITAL_MAGNIFICATION; _lowResolutionBrushTransform.ScaleX = lowResolutionToHighResolutionCropScale; _lowResolutionBrushTransform.ScaleY = lowResolutionToHighResolutionCropScale; // Show photo information in InformationTextBlock SetupInformationPanel(); }
private void BeginSession(Stream image) { System.Diagnostics.Debug.WriteLine("Begin session"); // Initialize session with image using (var memoryStream = new MemoryStream()) { image.Position = 0; image.CopyTo(memoryStream); try { // Some streams do not support flushing image.Flush(); } catch (Exception) { } memoryStream.Position = 0; // Initialize image source _source = new StreamImageSource(memoryStream); // Get image info Task.Run(async () => { _info = await _source.GetInfoAsync(); }).Wait(); // Create crop filter effect _reframingFilter = new ReframingFilter(); _filterEffect = new FilterEffect(_source) { Filters = new List<IFilter>() { _reframingFilter } }; // Create renderer _renderer = new WriteableBitmapRenderer(_filterEffect, _highResolutionCropBitmap); } // Set _lowResolutionBitmap decoding to a quite low resolution and initialize it with image if (_info.ImageSize.Width >= _info.ImageSize.Height) { _lowResolutionBitmap.DecodePixelWidth = 1536; _lowResolutionBitmap.DecodePixelHeight = 0; } else { _lowResolutionBitmap.DecodePixelWidth = 0; _lowResolutionBitmap.DecodePixelHeight = 1536; } image.Position = 0; _lowResolutionBitmap.SetSource(image); // Set LowResolutionCropBrush scaling so that it matches with the pixel perfect HighResolutionCropImage renderings var screenScaleFactor = App.Current.Host.Content.ScaleFactor / 100.0; var lowResolutionToHighResolutionCropScale = _info.ImageSize.Width / _lowResolutionBitmap.PixelWidth / screenScaleFactor * DIGITAL_MAGNIFICATION; _lowResolutionBrushTransform.ScaleX = lowResolutionToHighResolutionCropScale; _lowResolutionBrushTransform.ScaleY = lowResolutionToHighResolutionCropScale; // Show photo information in InformationTextBlock SetupInformationPanel(); }
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."); } }
private void BeginSession(Stream image) { // Initialize session with image using (var memoryStream = new MemoryStream()) { image.Position = 0; image.CopyTo(memoryStream); try { // Some streams do not support flushing image.Flush(); } catch (Exception ex) { } memoryStream.Position = 0; // Initialize image source _source = new StreamImageSource(memoryStream); // Get image info Task.Run(async () => { _info = await _source.GetInfoAsync(); }).Wait(); // Set _lowResolutionBitmap decoding to a quite low resolution and initialize it with image if (_info.ImageSize.Width >= _info.ImageSize.Height) { _bitmap.DecodePixelWidth = 1536; _bitmap.DecodePixelHeight = 0; } else { _bitmap.DecodePixelWidth = 0; _bitmap.DecodePixelHeight = 1536; } image.Position = 0; _bitmap.SetSource(image); } }
private void EndSession() { if (_source != null) { _source.Dispose(); _source = null; } _info = null; }
private void EndSession() { if (_renderer != null) { _renderer.Dispose(); _renderer = null; } if (_filterEffect != null) { _filterEffect.Dispose(); _filterEffect = null; } if (_source != null) { _source.Dispose(); _source = null; } _reframingFilter = null; _info = null; }
private IImageProvider Crop(BitmapImageSource overlayBitmapImageSource, ImageProviderInfo originalOverlayImageProviderInfo, int backgroundWidth, int backgroundHeight) { IImageProvider imageProvider; int overlayWidth = (int)overlayBitmapImageSource.Bitmap.Dimensions.Width; int overlayHeight = (int)overlayBitmapImageSource.Bitmap.Dimensions.Height; if (HorizontalAlignment != HorizontalAlignment.None) { int cropLeft = 0; int cropTop = 0; int cropWidth = Math.Min(overlayWidth, (int)originalOverlayImageProviderInfo.ImageSize.Width); int cropHeight = Math.Min(overlayHeight, (int)originalOverlayImageProviderInfo.ImageSize.Height); if ((HorizontalAlignment == HorizontalAlignment.Center) && (overlayWidth < (int)originalOverlayImageProviderInfo.ImageSize.Width)) { cropLeft = Math.Abs(overlayWidth / 2 - backgroundWidth / 2); cropWidth -= cropLeft * 2; } if ((VerticalAlignment == HorizontalAlignment.Center) && (overlayHeight < (int)originalOverlayImageProviderInfo.ImageSize.Height)) { cropTop = Math.Abs(overlayHeight / 2 - backgroundHeight / 2); cropHeight -= cropTop * 2; } imageProvider = new CropEffect(new Rect(cropLeft, cropTop, cropWidth, cropHeight)); } else { imageProvider = overlayBitmapImageSource; } return imageProvider; }
async Task createLRPicture(IImageProvider source, ImageProviderInfo info) { HR_LR_Factor = 4096 / Math.Max(info.ImageSize.Width, info.ImageSize.Height); if (HR_LR_Factor > 1) HR_LR_Factor = 1; InputLR = new WriteableBitmap( (int)(HR_LR_Factor * info.ImageSize.Width), (int)(HR_LR_Factor * info.ImageSize.Height) ); int LRblocksize = 4096/4; double blocksize = LRblocksize / HR_LR_Factor; var bitmapLR =new Bitmap( new Size(InputLR.PixelWidth, InputLR.PixelHeight), ColorMode.Bgra8888, (uint)(4*InputLR.PixelWidth), InputLR.Pixels.AsBuffer()); var tmpBitmp = new WriteableBitmap(LRblocksize, LRblocksize); for (int y = 0; y < 4; ++y) { var tmpheight =(int) Math.Min((double)LRblocksize, InputLR.PixelHeight - y * LRblocksize); if (tmpheight<=0) break; for (int x = 0; x < 4; ++x) { var tmpWidth = (int)Math.Min((double)LRblocksize, InputLR.PixelWidth - x * LRblocksize); if (tmpWidth <= 0) break; var tmp = new Bitmap(bitmapLR, new Rect((double)x * LRblocksize, (double)y * LRblocksize, tmpWidth, tmpheight )); using (var filter = new FilterEffect(source)) using (var render = new BitmapRenderer(filter, tmp)) { filter.Filters = new IFilter[] { new ReframingFilter(new Rect((double)x * blocksize, (double)y * blocksize, (double)blocksize, (double)blocksize), 0) }; await render.RenderAsync(); } } } }