Esempio n. 1
0
        public void FromNewImage(Stream image, PhotoOrigin origin)
        {
            _saved  = false;
            _origin = origin;

            if (_path != null)
            {
                _originalPath   = _path;
                _originalOrigin = _origin;
            }
            else if (_image != null && _originalPath == null) // Re-framed unsaved photo, save original photo to temporary folder
            {
                StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
                var           filename    = "captured.jpg";
                _image.Position = 0;
                Task.Run(async() =>
                {
                    using (var stream = await localFolder.OpenStreamForWriteAsync(filename, CreationCollisionOption.ReplaceExisting))
                    {
                        await _image.CopyToAsync(stream);
                    }
                }).Wait();
                _originalPath = localFolder.Path + "\\" + filename;
            }

            Image = image;
            Path  = null;
        }
Esempio n. 2
0
        public async Task FromLibraryPath(string path)
        {
            _saved  = true;
            _origin = PhotoOrigin.Library;
            StorageFile file = null;

            // Find matching high resolution photo if available
            if (!path.Contains(HIGH_RESOLUTION_PHOTO_SUFFIX))
            {
                string highResolutionPath = path.Replace(".jpg", HIGH_RESOLUTION_PHOTO_SUFFIX + ".jpg");
                try
                {
                    file = await StorageFile.GetFileFromPathAsync(highResolutionPath);

                    Path = highResolutionPath;
                }
                catch (FileNotFoundException)
                {
                }
            }
            if (file == null)
            {
                file = await StorageFile.GetFileFromPathAsync(path);

                Path = path;
            }
            Image = await file.OpenStreamForReadAsync();
        }
Esempio n. 3
0
        public async void RevertOriginal()
        {
            StorageFile file = await StorageFile.GetFileFromPathAsync(_originalPath);

            Stream stream = await file.OpenStreamForReadAsync();

            Image = stream;
            var tmp = _originalPath;

            _originalPath = null;
            _origin       = _originalOrigin;
            _saved        = tmp != null;
            Path          = tmp;
        }
Esempio n. 4
0
 public async void RevertOriginal()
 {
     StorageFile file = await StorageFile.GetFileFromPathAsync(_originalPath);
     Stream stream = await file.OpenStreamForReadAsync();
     Image = stream;
     var tmp = _originalPath;
     _originalPath = null;
     _origin = _originalOrigin;
     _saved = tmp != null;
     Path = tmp;
 }
Esempio n. 5
0
        public void FromNewImage(Stream image, PhotoOrigin origin)
        {
            _saved = false;
            _origin = origin;

            if (_path != null)
            {
                _originalPath = _path;
                _originalOrigin = _origin;
            }
            else if (_image != null && _originalPath == null) // Re-framed unsaved photo, save original photo to temporary folder
            {
                StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
                var filename = "captured.jpg";
                _image.Position = 0;
                Task.Run(async () =>
                {
                    using (var stream = await localFolder.OpenStreamForWriteAsync(filename, CreationCollisionOption.ReplaceExisting))
                    {
                        await _image.CopyToAsync(stream);
                    }
                }).Wait();
                _originalPath = localFolder.Path + "\\" + filename;
            }

            Image = image;
            Path = null;
        }
Esempio n. 6
0
        public async Task FromLibraryPath(string path)
        {
            _saved = true;
            _origin = PhotoOrigin.Library;
            StorageFile file = null;

            // Find matching high resolution photo if available
            if (!path.Contains(HIGH_RESOLUTION_PHOTO_SUFFIX))
            {
                string highResolutionPath = path.Replace(".jpg", HIGH_RESOLUTION_PHOTO_SUFFIX + ".jpg");
                try
                {
                    file = await StorageFile.GetFileFromPathAsync(highResolutionPath);
                    Path = highResolutionPath;
                }
                catch (FileNotFoundException)
                {
                }
            }
            if (file == null)
            {
                file = await StorageFile.GetFileFromPathAsync(path);
                Path = path;
            }
            Image = await file.OpenStreamForReadAsync();
        }