Ejemplo n.º 1
0
        private static async void DecryptFile(TLSecureFile secureFile, TLInputFileLocationBase inputFileLocation, string localFileName, string previewFileName)
        {
            var fileSecret = Passport.DecryptValueSecret(
                secureFile.Secret,
                EnterPasswordViewModel.Secret,
                secureFile.FileHash);

            var encryptedFile = await ApplicationData.Current.LocalFolder.GetFileAsync(inputFileLocation.GetFileName("document"));

            var decryptedTuple = await Passport.DecryptFile(localFileName, encryptedFile, fileSecret, secureFile.FileHash);

            var stream = await decryptedTuple.Item1.OpenReadAsync();

            await DialogDetailsViewModel.ResizeJpeg(stream, 180, localFileName, previewFileName);

            Telegram.Api.Helpers.Execute.BeginOnUIThread(() =>
            {
                secureFile.NotifyOfPropertyChange(() => secureFile.Self);
            });
        }
Ejemplo n.º 2
0
        public async void SetFile(StorageFile result, PhotoFile file)
        {
            if (result == null)
            {
                return;
            }

            _result = result;
            var properties = await result.Properties.GetImagePropertiesAsync();

            if (properties != null &&
                properties.Width > 0 &&
                properties.Height > 0)
            {
                _width  = properties.Width;
                _height = properties.Height;
                if (_width == 0 || _height == 0)
                {
                    return;
                }

                var minDimension = Math.Min(_width, _height);
                ImageBorder.Width  = _width * 400.0 / minDimension;
                ImageBorder.Height = _height * 400.0 / minDimension;
                ImageBorder.Margin = new Thickness((400.0 - ImageBorder.Width) / 2.0, (400.0 - ImageBorder.Height) / 2.0,
                                                   (400.0 - ImageBorder.Width) / 2.0, (400.0 - ImageBorder.Height) / 2.0);

                _stopwatch = Stopwatch.StartNew();
                var stream = await result.GetThumbnailAsync(ThumbnailMode.SingleItem, 800);

                System.Diagnostics.Debug.WriteLine("Picture.OpenReadAsync=" + _stopwatch.Elapsed);

                var thumbnailSource = new BitmapImage();
                //thumbnailSource.DecodePixelHeight = (int) ImageBorder.Height * 3;
                //thumbnailSource.DecodePixelWidth = (int) ImageBorder.Width * 3;
                thumbnailSource.CreateOptions = BitmapCreateOptions.BackgroundCreation;
                thumbnailSource.SetSource(stream.AsStream());
                Image.Source = thumbnailSource;
            }
            else
            {
                var sourceStream = await result.OpenReadAsync();

                var decoder = await BitmapDecoder.CreateAsync(sourceStream);

                _width  = decoder.OrientedPixelWidth;
                _height = decoder.OrientedPixelHeight;
                if (_width == 0 || _height == 0)
                {
                    return;
                }

                var minDimension = Math.Min(_width, _height);
                ImageBorder.Width  = _width * 400.0 / minDimension;
                ImageBorder.Height = _height * 400.0 / minDimension;
                ImageBorder.Margin = new Thickness((400.0 - ImageBorder.Width) / 2.0, (400.0 - ImageBorder.Height) / 2.0,
                                                   (400.0 - ImageBorder.Width) / 2.0, (400.0 - ImageBorder.Height) / 2.0);

                _stopwatch = Stopwatch.StartNew();
                var resizedJpeg = await DialogDetailsViewModel.ResizeJpeg(sourceStream, 800, string.Empty, string.Empty);

                var stream = new MemoryStream(resizedJpeg.Bytes);

                System.Diagnostics.Debug.WriteLine("Picture.OpenReadAsync=" + _stopwatch.Elapsed);

                var thumbnailSource = new BitmapImage();
                //thumbnailSource.DecodePixelHeight = (int) ImageBorder.Height * 3;
                //thumbnailSource.DecodePixelWidth = (int) ImageBorder.Width * 3;
                thumbnailSource.CreateOptions = BitmapCreateOptions.BackgroundCreation;
                thumbnailSource.SetSource(stream);
                Image.Source = thumbnailSource;
            }
        }