简体   繁体   English

UWP 从 BitmapImage 获取字节或像素

[英]UWP get bytes or pixels from BitmapImage

I have to make parallel work (of course async Task) that blur images selected from folder, so I have found this (BitmapImage), but the problem is what i do not know how to access bytes or pixels of this object, so that I can change them, blur or something else:我必须进行并行工作(当然是异步任务)来模糊从文件夹中选择的图像,所以我找到了这个(BitmapImage),但问题是我不知道如何访问这个 object 的字节或像素,所以我可以改变它们,模糊或其他:

var folderPicker = new Windows.Storage.Pickers.FolderPicker();
            folderPicker.FileTypeFilter.Add(".jpg");
            folderPicker.FileTypeFilter.Add(".jpeg");
            folderPicker.FileTypeFilter.Add(".png");

            var folder = await folderPicker.PickSingleFolderAsync();
            var filesList = await folder.GetFilesAsync();



            for (int i = 0; i < filesList.Count; i++)
            {
                using (var stream = await filesList[i].OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
//Here I will use some array of BitmapImage 
                    var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    await bitmapImage.SetSourceAsync(stream);

                    //show Image on Form
                    imageSourceForm.Source = bitmapImage;
                }

            }


So is there any way to get pixels or bytes of this object, or maybe do you know what to use that I can do work, but with async Task.那么有什么方法可以获取这个 object 的像素或字节,或者你知道我可以使用什么来工作,但是使用异步任务。 The most important part is that UI Thread has to be responsive, while the images are blurring.最重要的部分是 UI 线程必须是响应式的,而图像是模糊的。 Thanks in advance.提前致谢。

You could use the following code to get bytes of an image:您可以使用以下代码获取图像的字节数:

var random = await Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(filesList[i]).OpenReadAsync();
Windows.Graphics.Imaging.BitmapDecoder decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(random);
Windows.Graphics.Imaging.PixelDataProvider pixelData = await decoder.GetPixelDataAsync();

//Access pixel buffer in such a way
byte[] bytes = pixelData.DetachPixelData();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM