privateasyncvoid picker_Click_1(object sender, RoutedEventArgs e)
{
FileOpenPicker imgPicker = newFileOpenPicker();
imgPicker.FileTypeFilter.Add(".bmp");
imgPicker.FileTypeFilter.Add(".jpeg");
imgPicker.FileTypeFilter.Add(".gif");
imgPicker.FileTypeFilter.Add(".png");
imgPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
StorageFile imgFile = await imgPicker.PickSingleFileAsync();
try
{
IRandomAccessStreamWithContentType img = await imgFile.OpenReadAsync();
BitmapImage bmi = newBitmapImage();
bmi.SetSource(img);
ImgContainer.Source = bmi; // show original image in MainPage
// Fetching pixel data
using (IRandomAccessStream fileStream = await imgFile.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
//await bmpimg.SetSourceAsync(fileStream);
//prevF2.Source = bmpimg;
BitmapDecoder decoder = awaitBitmapDecoder.CreateAsync(fileStream);
// Scale image to appropriate size
BitmapTransform transform = newBitmapTransform()
{
ScaledWidth = Convert.ToUInt32(bmi.PixelWidth),
ScaledHeight =Convert.ToUInt32(bmi.PixelHeight)
};
/// RGBA8 format:
/// Each pixel is store in 4 consecutive bytes:
/// 1st byte is Red (no offset)
/// 2nd byte is Green (+1)
/// 3rd byte is Blue (+2)
/// 4th byte is Alpha (+3)
PixelDataProvider pixelData = await decoder.GetPixelDataAsync(
BitmapPixelFormat.Rgba8,
BitmapAlphaMode.Straight,
transform,
ExifOrientationMode.IgnoreExifOrientation,// This sample ignores Exif orientation
ColorManagementMode.DoNotColorManage
);
// An array containing the decoded image data,
// which could be modified before being displayed
sourcePixels = pixelData.DetachPixelData();
width = decoder.PixelWidth;
height= decoder.PixelHeight;
grayScale.IsEnabled = true;
}
}
catch
{
// do nothing
}