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


C# WriteableBitmap.SetSource方法代码示例

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


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

示例1: ToBitmapImageAsync

        public async static Task<WriteableBitmap> ToBitmapImageAsync(this byte[] imageBytes, Tuple<int, int> downscale)
        {
            if (imageBytes == null)
                return null;

            IRandomAccessStream image = imageBytes.AsBuffer().AsStream().AsRandomAccessStream();

            if (downscale != null && (downscale.Item1 > 0 || downscale.Item2 > 0))
            {
                image = await image.ResizeImage((uint)downscale.Item1, (uint)downscale.Item2);
            }

            using (image)
            {
                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(image);

                image.Seek(0);

                WriteableBitmap bitmap = null;

                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
                {
                    bitmap = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);
                    bitmap.SetSource(image);
                });

                return bitmap;
            }
        }
开发者ID:zenjoy,项目名称:FFImageLoading,代码行数:29,代码来源:ImageExtensions.cs

示例2: clipboard

        public async Task<string> clipboard(DataPackageView con)
        {
            string str = string.Empty;
            //文本
            if (con.Contains(StandardDataFormats.Text))
            {
                str = await con.GetTextAsync();
                return str;
            }

            //图片
            if (con.Contains(StandardDataFormats.Bitmap))
            {
                RandomAccessStreamReference img = await con.GetBitmapAsync();
                var imgstream = await img.OpenReadAsync();
                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(imgstream);

                WriteableBitmap src = new WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight);
                src.SetSource(imgstream);

                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(imgstream);
                PixelDataProvider pxprd =
                    await
                        decoder.GetPixelDataAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight,
                            new BitmapTransform(), ExifOrientationMode.RespectExifOrientation,
                            ColorManagementMode.DoNotColorManage);
                byte[] buffer = pxprd.DetachPixelData();

                str = "image";
                StorageFolder folder = await _folder.GetFolderAsync(str);

                StorageFile file =
                    await
                        folder.CreateFileAsync(
                            DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() +
                            DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() +
                            (ran.Next()%10000).ToString() + ".png", CreationCollisionOption.GenerateUniqueName);

                using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);
                    encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, decoder.PixelWidth,
                        decoder.PixelHeight, decoder.DpiX, decoder.DpiY, buffer);
                    await encoder.FlushAsync();

                    str = $"![这里写图片描述](image/{file.Name})\n";
                }
            }

            //文件
            if (con.Contains(StandardDataFormats.StorageItems))
            {
                var filelist = await con.GetStorageItemsAsync();
                StorageFile file = filelist.OfType<StorageFile>().First();
                return await imgfolder(file);
            }

            return str;
        }
开发者ID:lindexi,项目名称:Markdown,代码行数:60,代码来源:model.cs

示例3: LoadImageAsync

        public async Task<BitmapSource> LoadImageAsync(Stream imageStream, Uri uri)
        {
            if (imageStream == null)
            {
                return null;
            }

            var stream = new InMemoryRandomAccessStream();
            imageStream.CopyTo(stream.AsStreamForWrite());
            stream.Seek(0);

            BitmapImage bitmap = new BitmapImage();
            await bitmap.SetSourceAsync(stream);

            // convert to a writable bitmap so we can get the PixelBuffer back out later...
            // in case we need to edit and/or re-encode the image.
            WriteableBitmap bmp = new WriteableBitmap(bitmap.PixelHeight, bitmap.PixelWidth);
            stream.Seek(0);
            bmp.SetSource(stream);

            List<Byte> allBytes = new List<byte>();
            byte[] buffer = new byte[4000];
            int bytesRead = 0;
            while ((bytesRead = await imageStream.ReadAsync(buffer, 0, 4000)) > 0)
            {
                allBytes.AddRange(buffer.Take(bytesRead));
            }

            DataContainerHelper.Instance.WriteableBitmapToStorageFile(bmp, uri);

            return bmp;
        }
开发者ID:wpFaizK,项目名称:Windows-Universal-UWP-,代码行数:32,代码来源:DownloadHelper.cs

示例4: LoadWriteableBitmap

 /// <summary>
 /// Return WriteableBitmap object from a given path
 /// </summary>
 /// <param name="relativePath">file path</param>
 /// <returns>WriteableBitmap</returns>
 public static async Task<WriteableBitmap> LoadWriteableBitmap(string relativePath)
 {
     var storageFile = await Package.Current.InstalledLocation.GetFileAsync(relativePath.Replace('/', '\\'));
     var stream = await storageFile.OpenReadAsync();
     var wb = new WriteableBitmap(1, 1);
     wb.SetSource(stream);
     return wb;
 }
开发者ID:EdiWang,项目名称:UWP-Helpers,代码行数:13,代码来源:BitmapExtensions.cs

示例5: RetrieveAndPutBitmapAsync

 public async Task<WriteableBitmap> RetrieveAndPutBitmapAsync(StorageFile file)
 {
     IRandomAccessStream contents = await file.OpenAsync(FileAccessMode.Read);
     WriteableBitmap bitmap = new WriteableBitmap(100, 100);
     bitmap.SetSource(contents);
     _cache.Add(new BitmapCacheItem() { StorageFile = file, Bitmap = bitmap });
     Debug.WriteLine("Caching bitmap for file: " + file.Path + "::" + file.Name);
     return bitmap;
 }
开发者ID:Ronacs,项目名称:WinDevCamp,代码行数:9,代码来源:BitmapCache.cs

示例6: LoadBitmap

 private async Task LoadBitmap(IRandomAccessStream stream)
 {
     _writeableBitmap = new WriteableBitmap(1, 1);
     _writeableBitmap.SetSource(stream);
     _writeableBitmap.Invalidate();
     await Dispatcher.RunAsync(
         Windows.UI.Core.CoreDispatcherPriority.Normal,
         () => ImageTarget.Source = _writeableBitmap);
 }
开发者ID:TriagePic,项目名称:TriagePic-WinStore,代码行数:9,代码来源:WebcamPage.xaml.cs

示例7: OnNavigatedTo

      protected override async void OnNavigatedTo(NavigationEventArgs e)
      {
         try
         {
            var cameras = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
            if (cameras.Count < 1)
            {
               Error.Text = "No camera found, decoding static image";
               await DecodeStaticResource();
               return;
            }
            MediaCaptureInitializationSettings settings;
            if (cameras.Count == 1)
            {
               settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameras[0].Id }; // 0 => front, 1 => back
            }
            else
            {
               settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameras[1].Id }; // 0 => front, 1 => back
            }

            await _mediaCapture.InitializeAsync(settings);
            VideoCapture.Source = _mediaCapture;
            await _mediaCapture.StartPreviewAsync();

            while (_result == null)
            {
               var photoStorageFile = await KnownFolders.PicturesLibrary.CreateFileAsync("scan.jpg", CreationCollisionOption.GenerateUniqueName);
               await _mediaCapture.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), photoStorageFile);

               var stream = await photoStorageFile.OpenReadAsync();
               // initialize with 1,1 to get the current size of the image
               var writeableBmp = new WriteableBitmap(1, 1);
               writeableBmp.SetSource(stream);
               // and create it again because otherwise the WB isn't fully initialized and decoding
               // results in a IndexOutOfRange
               writeableBmp = new WriteableBitmap(writeableBmp.PixelWidth, writeableBmp.PixelHeight);
               stream.Seek(0);
               writeableBmp.SetSource(stream);

               _result = ScanBitmap(writeableBmp);

               await photoStorageFile.DeleteAsync(StorageDeleteOption.PermanentDelete);
            }

            await _mediaCapture.StopPreviewAsync();
            VideoCapture.Visibility = Visibility.Collapsed;
            CaptureImage.Visibility = Visibility.Visible;
            ScanResult.Text = _result.Text;
         }
         catch (Exception ex)
         {
            Error.Text = ex.Message;
         }
      }
开发者ID:n1rvana,项目名称:ZXing.NET,代码行数:55,代码来源:MainPage.xaml.cs

示例8: LoadImage

        private async Task LoadImage(StorageFile file)
        {
            ImageProperties imgProp = await file.Properties.GetImagePropertiesAsync();

            using (var imgStream = await file.OpenAsync(FileAccessMode.Read))
            {
                bitmap = new WriteableBitmap((int)imgProp.Width, (int)imgProp.Height);
                bitmap.SetSource(imgStream);
                PreviewImage.Source = bitmap;
            }
        }
开发者ID:sarthakbhol,项目名称:Windows10AppSamples,代码行数:11,代码来源:MainPage.xaml.cs

示例9: LoadIcon

        private static async Task<BandIcon> LoadIcon(string uri)
        {
            var imageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(uri));

            using (var fileStream = await imageFile.OpenAsync(FileAccessMode.Read))
            {
                var bitmap = new WriteableBitmap(1, 1);
                bitmap.SetSource(fileStream);
                return bitmap.ToBandIcon();
            }
        }
开发者ID:icebeam7,项目名称:Ahorcado_Estados,代码行数:11,代码来源:EstadosMSBand.cs

示例10: LoadImage

        public static async Task<WriteableBitmap> LoadImage(StorageFile file)
        {
            ImageProperties imgProp = await file.Properties.GetImagePropertiesAsync();

            using (var imgStream = await file.OpenAsync(FileAccessMode.Read))
            {
                WriteableBitmap writeablebitmap = new WriteableBitmap((int)imgProp.Width, (int)imgProp.Height);
                writeablebitmap.SetSource(imgStream);
                return writeablebitmap;
            } 

        }
开发者ID:7ung,项目名称:LanguageDetectApp,代码行数:12,代码来源:Util.cs

示例11: Load

        async void Load(string filename)
        {
            var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(filename);

            using (var stream = await file.OpenReadAsync())
            {
                var bmp = new WriteableBitmap(width, height);
                bmp.SetSource(stream);

                internalBuffer = bmp.PixelBuffer.ToArray();
            }
        }
开发者ID:padzikm,项目名称:ComputerGraphics,代码行数:12,代码来源:Texture.cs

示例12: OnNavigatedTo

        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {
                var cameras = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
                if (cameras.Count < 1)
                {
                    await DecodeStaticResource();
                    return;
                }
                MediaCaptureInitializationSettings settings;
                settings = cameras.Count == 1 ? new MediaCaptureInitializationSettings { VideoDeviceId = cameras[0].Id } : new MediaCaptureInitializationSettings { VideoDeviceId = cameras[1].Id };

                await _mediaCapture.InitializeAsync(settings);
                VideoCapture.Source = _mediaCapture;
                await _mediaCapture.StartPreviewAsync();

                while (_result == null)
                {
                    var photoStorageFile = await KnownFolders.PicturesLibrary.CreateFileAsync("scan.jpg", CreationCollisionOption.GenerateUniqueName);
                    await _mediaCapture.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), photoStorageFile);

                    var stream = await photoStorageFile.OpenReadAsync();
                    // initialize with 1,1 to get the current size of the image
                    var writeableBmp = new WriteableBitmap(1, 1);
                    writeableBmp.SetSource(stream);
                    // and create it again because otherwise the WB isn't fully initialized and decoding
                    // results in a IndexOutOfRange
                    writeableBmp = new WriteableBitmap(writeableBmp.PixelWidth, writeableBmp.PixelHeight);
                    stream.Seek(0);
                    writeableBmp.SetSource(stream);

                    _result = ScanBitmap(writeableBmp);

                    if (_result != null)
                    {
                        if (!_barcodeFound)
                        {
                            Messenger.Default.Send(new NotificationMessage(_result, "ResultFoundMsg"));
                            _barcodeFound = true;
                        }
                    }

                    await photoStorageFile.DeleteAsync(StorageDeleteOption.PermanentDelete);
                }

                await _mediaCapture.StopPreviewAsync();
            }
            catch (Exception ex)
            {
                var s = "";
            }
        }
开发者ID:ntomlinson,项目名称:StoreCardBuddy,代码行数:53,代码来源:ScanBarcodeView.xaml.cs

示例13: OnLoadImage

        private async void OnLoadImage(IRandomAccessStream imageStream)
        {
            var image = new WriteableBitmap(1, 1);

            image.SetSource(imageStream);

            ComicImage.Source = image;

            ComicImage.Width = 400;
            ComicImage.Height = 300;

            imageStream.Dispose();
        }
开发者ID:DavidBasarab,项目名称:FatCatComics,代码行数:13,代码来源:MainPage.xaml.cs

示例14: StorageFileToWriteableBitmap

        public static async Task<WriteableBitmap> StorageFileToWriteableBitmap(StorageFile file)
        {
            if (file == null)
                return null;
            WriteableBitmap bmp;
            using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read))
            {
                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
                bmp = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);

                bmp.SetSource(stream);
            }
            return bmp;
        }
开发者ID:chenjianwp,项目名称:UWP_ToolKit_CommonLibrary,代码行数:14,代码来源:ImageHelper.cs

示例15: LoadImage

       private async Task<Mat> LoadImage(String imageUri)
       {

          StorageFile file =
             await Package.Current.InstalledLocation.GetFileAsync(imageUri);
          using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read))
          
          {
             BitmapImage bmpImage = new BitmapImage();
             bmpImage.SetSource(fileStream);
             
             WriteableBitmap bmp = new WriteableBitmap(bmpImage.PixelWidth, bmpImage.PixelHeight);
             bmp.SetSource(await file.OpenAsync(FileAccessMode.Read));

             Mat img = new Mat(bmp);
            
             return img;

          }
       }
开发者ID:reidblomquist,项目名称:emgucv,代码行数:20,代码来源:ItemPage.xaml.cs


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