private async void selectSourceImage_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                _sourceImageFile = await SelectSourceImageFile();

                ImageDisplay = await ToImageConverter.Convert(_sourceImageFile, ImageDisplay);

                _sourceImage = ToWriteableBitmapConverter.ConvertToWriteableBitmap(ImageDisplay);
            }
            catch (Exception)
            {
                await FailedSelectionDialog();
            }
        }
        private async void selectImageToEmbedWith_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                _embedImageFile = await SelectSourceImageFile();

                EmbedDisplay = await ToImageConverter.Convert(_embedImageFile, EmbedDisplay);

                _embedImage = ToWriteableBitmapConverter.ConvertToWriteableBitmap(EmbedDisplay);
            }
            catch (Exception)
            {
                await FailedSelectionDialog();
            }
        }
        private async void extractImageButton_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                var image = await ImageEmbedder.ExtractHiddenImage(
                    ToWriteableBitmapConverter.ConvertToWriteableBitmap(ImageDisplay),
                    _sourceImageFile);

                _imageResult          = ToWriteableBitmapConverter.ConvertToWriteableBitmap(image);
                EncryptedImage.Source = _imageResult;
                await CustomDialog("Next, save the image to view the hidden message!");
            }
            catch (Exception)
            {
                await CustomDialog("There are no secrets behind this image");
            }
        }
Пример #4
0
        public static async Task <Image> EncryptAsync(Image image, StorageFile sourceImageFile)
        {
            var imageToEncrypt = ToWriteableBitmapConverter.ConvertToWriteableBitmap(image);

            using (var fileStream = await sourceImageFile.OpenAsync(FileAccessMode.Read))
            {
                var decoder = await BitmapDecoder.CreateAsync(fileStream);

                var transform = new BitmapTransform
                {
                    ScaledWidth  = Convert.ToUInt32(imageToEncrypt.PixelWidth),
                    ScaledHeight = Convert.ToUInt32(imageToEncrypt.PixelHeight)
                };

                var pixelData = await decoder.GetPixelDataAsync(
                    BitmapPixelFormat.Bgra8,
                    BitmapAlphaMode.Straight,
                    transform,
                    ExifOrientationMode.IgnoreExifOrientation,
                    ColorManagementMode.DoNotColorManage
                    );


                var sourcePixels = pixelData.DetachPixelData();

                var encryptedImage = Encrypt(sourcePixels, decoder);

                using (var writeStream = imageToEncrypt.PixelBuffer.AsStream())
                {
                    await writeStream.WriteAsync(encryptedImage, 0, encryptedImage.Length);

                    image.Source = imageToEncrypt;
                    return(image);
                }
            }
        }