public static byte[] GetFirstQuadrant(this byte[] source, uint oriPixelWidth, uint oriPixelHeight) { var extract = new ExtractImage(); extract.ExtractWholeImage(source, oriPixelWidth, oriPixelHeight); var first = (source.Length / 2) / 2; return(source.Take(first).ToArray()); }
private async void LoadPictureButton_Click(object sender, RoutedEventArgs e) { var imageExtract = new ExtractImage(); var textExtract = new ExtractText(); var sourceImageFile = await FileOption.SelectSourceImageFile(); if (sourceImageFile == null) { return; } var copyBitmapImage = await sourceImageFile.MakeCopyOfImage(); using (var fileStream = await sourceImageFile.OpenAsync(FileAccessMode.Read)) { var decoder = await BitmapDecoder.CreateAsync(fileStream); var transform = new BitmapTransform { ScaledWidth = Convert.ToUInt32(copyBitmapImage.PixelWidth), ScaledHeight = Convert.ToUInt32(copyBitmapImage.PixelHeight) }; var pixelData = await decoder.GetPixelDataAsync( BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, transform, ExifOrientationMode.IgnoreExifOrientation, ColorManagementMode.DoNotColorManage ); var sourceOriPixels = pixelData.DetachPixelData(); var firstPixelcolor = PixelColor.GetPixelBgra8(sourceOriPixels, 0, 0, decoder.PixelWidth, decoder.PixelHeight); var secondPixelcolor = PixelColor.GetPixelBgra8(sourceOriPixels, 0, 1, decoder.PixelWidth, decoder.PixelHeight); if (firstPixelcolor.R == 119 && firstPixelcolor.G == 119 && firstPixelcolor.B == 119 && (secondPixelcolor.R & 1) == 1) { this.messageTextBlock.Text = "There is a message here"; if ((secondPixelcolor.G & (1 << 1)) == 0) { this.textToEncryptBox.Text = textExtract.ExtractImageForText(sourceOriPixels, decoder.PixelWidth, decoder.PixelHeight); } else if ((secondPixelcolor.G & (1 << 0)) == 0) { this.textToEncryptBox.Text = textExtract.ExtractImageForTextwithTwoPixels(sourceOriPixels, decoder.PixelWidth, decoder.PixelHeight); } } else if (firstPixelcolor.R == 119 && firstPixelcolor.G == 119 && firstPixelcolor.B == 119 && (secondPixelcolor.R & 1) == 0) { this.messageTextBlock.Text = "There is a message here"; imageExtract.ExtractWholeImage(sourceOriPixels, decoder.PixelWidth, decoder.PixelHeight); this.decryptedImage = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight); using (var writeStream = this.decryptedImage.PixelBuffer.AsStream()) { await writeStream.WriteAsync(sourceOriPixels, 0, sourceOriPixels.Length); this.encrptedImage.Source = this.decryptedImage; } } else { this.messageTextBlock.Text = "There is no message here"; } this.imageToEncript = sourceImageFile; this.imageDisplayBox.Source = copyBitmapImage; } }