当前位置: 首页>>代码示例>>C#>>正文


C# WriteableBitmap.ToByteArray方法代码示例

本文整理汇总了C#中Windows.UI.Xaml.Media.Imaging.WriteableBitmap.ToByteArray方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.ToByteArray方法的具体用法?C# WriteableBitmap.ToByteArray怎么用?C# WriteableBitmap.ToByteArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.UI.Xaml.Media.Imaging.WriteableBitmap的用法示例。


在下文中一共展示了WriteableBitmap.ToByteArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AppBarBtnEdit_Click

        ///////////////////////////////////////////////////////////////////////////
        // Use the Nokia Imaging SDK to apply a filter to a selected image

        private async void AppBarBtnEdit_Click(object sender, RoutedEventArgs e)
        {
            progressRing.IsEnabled = true;
            progressRing.IsActive = true;
            progressRing.Visibility = Visibility.Visible;

            // Create NOK Imaging SDK effects pipeline and run it
            var imageStream = new BitmapImageSource(originalBitmap.AsBitmap());
            using (var effect = new FilterEffect(imageStream))
            {
                var filter = new Lumia.Imaging.Adjustments.GrayscaleFilter();
                effect.Filters = new[] { filter };
                
                // Render the image to a WriteableBitmap.
                var renderer = new WriteableBitmapRenderer(effect, originalBitmap);
                editedBitmap = await renderer.RenderAsync();
                editedBitmap.Invalidate();
            }

            Image.Source = originalBitmap;

            Image.Visibility = Visibility.Collapsed;

           

            //Resizing the editedBitmap to 128x128
            var resized1 = editedBitmap.Resize(128, 128, Windows.UI.Xaml.Media.Imaging.WriteableBitmapExtensions.Interpolation.Bilinear);

            //converting the editedBitmap to byte array
            byte[] edit_arr = resized1.ToByteArray();

            
            
            
            //obtaining the images folder
            StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
            StorageFolder subfolder = await folder.GetFolderAsync("Images");
         
            
            //create list of all the files in the images folder
            var pictures = await subfolder.GetFilesAsync();
            
            

            double ldiff = 50;//least percentage difference for an image to be a match
            string dispText = "Try again";//default message to be displayed

            byte threshold = 124;
            
            //process through all images 
            foreach (var file in pictures)
            {
                
                if (file != null)
                {
                    // Use WriteableBitmapEx to easily load image from a stream
                    using (var stream = await file.OpenReadAsync())
                    {
                        listBitmap = await new WriteableBitmap(1, 1).FromStream(stream);
                        stream.Dispose();
                    }

                    //convert obtained image to byte array
                    byte[] list_arr = listBitmap.ToByteArray();


                    byte[] difference = new byte[edit_arr.Length];

                    //compare byte array of both the images
                    for (int i=0;i<list_arr.Length;i++)
                    {
                        difference[i] = (byte)Math.Abs(edit_arr[i]-list_arr[i]);
                    }


                    //calculate percentage difference
                    int differentPixels = 0;

                    foreach(byte b in difference )
                    {
                        if (b > threshold)
                            differentPixels++;
                    }

                    double percentage = (double)differentPixels / (double)list_arr.Length;
                    percentage = percentage * 100;
                    

                    if (percentage <= ldiff)
                    {
                        ldiff = percentage;
                        dispText =file.DisplayName;
                    }
                }
            }

            tb.Text = dispText;
//.........这里部分代码省略.........
开发者ID:lorenzofar,项目名称:SLI,代码行数:101,代码来源:Interpret.xaml.cs


注:本文中的Windows.UI.Xaml.Media.Imaging.WriteableBitmap.ToByteArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。