示例#1
0
        protected override void OnUpdating(UltravioletTime time)
        {
            // ACTION: Save Image
            if (Ultraviolet.GetInput().GetActions().SaveImage.IsPressed() || (Ultraviolet.GetInput().GetPrimaryTouchDevice()?.WasTapped() ?? false))
            {
                content.Load <SoundEffect>(GlobalSoundEffectID.Shutter).Play();

                // The SurfaceSaver class contains platform-specific functionality needed to write image
                // data to streams. We can pass a render target directly to the SaveAsPng() or SaveAsJpg() methods.
                var saver = SurfaceSaver.Create();

                // The Android and iOS platforms have restrictions on where you can save files, so we'll just
                // save to the photo gallery on those devices. We'll use a partial method to implement
                // this platform-specific behavior.
                SaveImage(saver, rtarget);

                // Alternatively, we could populate an array with the target's data using the GetData() method...
                //     var data = new Color[rtarget.Width * rtarget.Height];
                //     rtarget.GetData(data);
            }

            // ACTION: Exit Application
            if (Ultraviolet.GetInput().GetActions().ExitApplication.IsPressed())
            {
                Exit();
            }

            // Fade out save confirmation message
            if (confirmMsgOpacity > 0)
            {
                confirmMsgOpacity -= (1.0 / 4.0) * time.ElapsedTime.TotalSeconds;
            }

            base.OnUpdating(time);
        }
示例#2
0
        /// <summary>
        /// Saves the surface as a PNG image to the specified stream.
        /// </summary>
        /// <param name="stream">The stream to which to save the image data.</param>
        public override void SaveAsPng(Stream stream)
        {
            Contract.Require(stream, nameof(stream));

            var saver = SurfaceSaver.Create();

            saver.SaveAsPng(this, stream);
        }
        /// <inheritdoc/>
        public override void SaveAsJpeg(Stream stream)
        {
            Contract.EnsureNotDisposed(this, Disposed);
            Contract.Require(stream, nameof(stream));

            var saver = SurfaceSaver.Create();

            saver.SaveAsJpeg(this, stream);
        }
示例#4
0
        partial void SaveImage(SurfaceSaver surfaceSaver, RenderTarget2D target)
        {
            var filename = $"output-{DateTime.Now:yyyyMMdd-HHmmss}.png";
            var path     = filename;

            using (var stream = File.OpenWrite(path))
                surfaceSaver.SaveAsPng(rtarget, stream);

            confirmMsgText    = $"Image saved to {filename}";
            confirmMsgOpacity = 1;
        }
示例#5
0
        partial void SaveImage(SurfaceSaver surfaceSaver, RenderTarget2D target)
        {
            var saver    = SurfaceSaver.Create();
            var filename = $"output-{DateTime.Now:yyyyMMdd-HHmmss}.png";
            var path     = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), filename);

            using (var stream = File.OpenWrite(path))
                saver.SaveAsPng(rtarget, stream);

            confirmMsgText    = $"Image saved to {path}";
            confirmMsgOpacity = 1;
        }
示例#6
0
        /// <inheritdoc/>
        protected override void OnUpdating(UltravioletTime time)
        {
            // ACTION: Save Image
            if (Ultraviolet.GetInput().GetActions().SaveImage.IsPressed() || (Ultraviolet.GetInput().GetTouchDevice()?.WasTapped() ?? false))
            {
                content.Load <SoundEffect>(GlobalSoundEffectID.Shutter).Play();

                // The SurfaceSaver class contains platform-specific functionality needed to write image
                // data to files. We can pass a render target directly to the SaveAsPng() or SaveAsJpg() methods.
                var saver    = SurfaceSaver.Create();
                var filename = $"output-{DateTime.Now:yyyyMMdd-HHmmss}.png";
                var path     = filename;

#if ANDROID
                var dir = Android.OS.Environment.GetExternalStoragePublicDirectory(
                    Android.OS.Environment.DirectoryPictures).AbsolutePath;
                path = Path.Combine(dir, filename);
#endif

                using (var stream = File.OpenWrite(path))
                    saver.SaveAsPng(rtarget, stream);

#if ANDROID
                Android.Media.MediaScannerConnection.ScanFile(ApplicationContext, new String[] { path },
                                                              new String[] { Android.Webkit.MimeTypeMap.Singleton.GetMimeTypeFromExtension("png") }, null);

                confirmMsgText    = $"Image saved to photo gallery";
                confirmMsgOpacity = 1;
#else
                confirmMsgText    = $"Image saved to {filename}";
                confirmMsgOpacity = 1;
#endif

                // Alternatively, we could populate an array with the target's data using the GetData() method...
                //     var data = new Color[rtarget.Width * rtarget.Height];
                //     rtarget.GetData(data);
            }

            // ACTION: Exit Application
            if (Ultraviolet.GetInput().GetActions().ExitApplication.IsPressed())
            {
                Exit();
            }

            // Fade out save confirmation message
            if (confirmMsgOpacity > 0)
            {
                confirmMsgOpacity -= (1.0 / 4.0) * time.ElapsedTime.TotalSeconds;
            }

            base.OnUpdating(time);
        }
示例#7
0
        partial void SaveImage(SurfaceSaver surfaceSaver, RenderTarget2D target)
        {
            var filename = $"output-{DateTime.Now:yyyyMMdd-HHmmss}.png";

            var dir = AndroidEnvironment.GetExternalStoragePublicDirectory(
                AndroidEnvironment.DirectoryPictures).AbsolutePath;
            var path = Path.Combine(dir, filename);

            using (var stream = File.OpenWrite(path))
                surfaceSaver.SaveAsPng(rtarget, stream);

            MediaScannerConnection.ScanFile(ApplicationContext, new String[] { path },
                                            new String[] { MimeTypeMap.Singleton.GetMimeTypeFromExtension("png") }, null);

            confirmMsgText    = $"Image saved to photo gallery";
            confirmMsgOpacity = 1;
        }
示例#8
0
        partial void SaveImage(SurfaceSaver surfaceSaver, RenderTarget2D target)
        {
            using (var stream = new MemoryStream())
            {
                surfaceSaver.SaveAsPng(rtarget, stream);
                stream.Flush();
                stream.Seek(0, SeekOrigin.Begin);

                using (var imgData = Foundation.NSData.FromStream(stream))
                    using (var img = UIKit.UIImage.LoadFromData(imgData))
                    {
                        img.SaveToPhotosAlbum(null);
                    }

                confirmMsgText    = $"Image saved to photo gallery";
                confirmMsgOpacity = 1;
            }
        }
        /// <inheritdoc/>
        public override void SaveAsPng(Stream stream)
        {
            Contract.EnsureNotDisposed(this, Disposed);
            Contract.Require(stream, nameof(stream));
            Contract.Ensure(IsComplete, SDL2Strings.SurfaceIsNotComplete);

            EnsureAllLayersMatchSrgbEncoding();

            var outputSurfaceOptions = SrgbEncoded ? SurfaceOptions.SrgbColor : SurfaceOptions.LinearColor;

            using (var outputSurface = Surface2D.Create(Width * Depth, Height, outputSurfaceOptions))
            {
                var position = 0;
                for (int i = 0; i < Depth; i++)
                {
                    GetLayer(i).Blit(outputSurface, new Rectangle(position, 0, Width, Height));
                    position += Width;
                }

                var surfaceSaver = SurfaceSaver.Create();
                surfaceSaver.SaveAsPng(outputSurface, stream);
            }
        }
示例#10
0
 partial void SaveImage(SurfaceSaver surfaceSaver, RenderTarget2D target);