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


C# WriteableBitmap.SetSourceAsync方法代码示例

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


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

示例1: ButtonFilePick_Click

        private async void ButtonFilePick_Click(object sender, RoutedEventArgs e)
        {
            var picker = new FileOpenPicker();
            picker.ViewMode = PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");

            StorageFile file = await picker.PickSingleFileAsync();


            if (file != null)
            {

                ImageProperties imgProp = await file.Properties.GetImagePropertiesAsync();
                var savedPictureStream = await file.OpenAsync(FileAccessMode.Read);

                //set image properties and show the taken photo
                bitmap = new WriteableBitmap((int)imgProp.Width, (int)imgProp.Height);
                await bitmap.SetSourceAsync(savedPictureStream);
                BBQImage.Source = bitmap;
                BBQImage.Visibility = Visibility.Visible;

                (this.DataContext as BBQRecipeViewModel).imageSource = file.Path;
            }
        }
开发者ID:cheahengsoon,项目名称:Windows10UWP-HandsOnLab,代码行数:27,代码来源:BBQRecipePage.xaml.cs

示例2: Page_Loaded

        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            await InitializeQrCode();
            var imgProp = new ImageEncodingProperties { Subtype = "BMP", Width = 600, Height = 800 };
            var bcReader = new BarcodeReader();

            while (true)
            {
                var stream = new InMemoryRandomAccessStream();
                await _mediaCapture.CapturePhotoToStreamAsync(imgProp, stream);

                stream.Seek(0);
                var wbm = new WriteableBitmap(600, 800);
                await wbm.SetSourceAsync(stream);

                var result = bcReader.Decode(wbm);

                if (result != null)
                {
                    var msgbox = new MessageDialog(result.Text);
                    await msgbox.ShowAsync();
                }
            }

        }
开发者ID:ddumic,项目名称:WP_8_1_helper,代码行数:25,代码来源:QRCode.xaml.cs

示例3: OCRAsync

        async Task<string> OCRAsync(byte[] buffer, uint width, uint height)
        {
            var bitmap = new WriteableBitmap((int)width, (int)height);

            var memoryStream = new MemoryStream(buffer);
            await bitmap.SetSourceAsync(memoryStream.AsRandomAccessStream());

            if (bitmap.PixelHeight < 40 ||
                bitmap.PixelHeight > 2600 ||
                bitmap.PixelWidth < 40 ||
                bitmap.PixelWidth > 2600)
                bitmap = await ResizeImage(bitmap, (uint)(bitmap.PixelWidth * .7), (uint)(bitmap.PixelHeight * .7));

            var ocrResult = await ocrEngine.RecognizeAsync((uint)bitmap.PixelHeight, (uint)bitmap.PixelWidth, bitmap.PixelBuffer.ToArray());

            if (ocrResult.Lines != null)
            {
                var extractedText = new StringBuilder();

                foreach (var line in ocrResult.Lines)
                {
                    foreach (var word in line.Words)
                        extractedText.Append(word.Text + " ");
                    extractedText.Append(Environment.NewLine);
                }

                return extractedText.ToString();
            }

            return null;
        }
开发者ID:SamirHafez,项目名称:Nutrition,代码行数:31,代码来源:WPOCRService.cs

示例4: ScanBarcodeAsync

        public async Task ScanBarcodeAsync(Windows.Storage.StorageFile file)
        {
            WriteableBitmap bitmap;
            BitmapDecoder decoder;
            using (IRandomAccessStream str = await file.OpenReadAsync())
            {
                decoder = await BitmapDecoder.CreateAsync(str);
                bitmap = new WriteableBitmap(Convert.ToInt32(decoder.PixelWidth), Convert.ToInt32(decoder.PixelHeight));
                await bitmap.SetSourceAsync(str);
            }

            lock (locker)
            {                
                ZXing.BarcodeReader reader = new ZXing.BarcodeReader();
                reader.Options.PossibleFormats = new ZXing.BarcodeFormat[] { ZXing.BarcodeFormat.CODE_128, ZXing.BarcodeFormat.QR_CODE, ZXing.BarcodeFormat.CODE_39 };
                reader.Options.TryHarder = true;
                reader.AutoRotate = true;
                var results = reader.Decode(bitmap);
                if (results == null)
                {
                    this.OnBarcodeScannCompleted(new BarcodeScanCompletedEventArgs(false, string.Empty));
                }
                else
                {
                    this.OnBarcodeScannCompleted(new BarcodeScanCompletedEventArgs(true, results.Text));
                }
            }
        }
开发者ID:CarstenCors,项目名称:BarcodeReader,代码行数:28,代码来源:BarcodeProxy.cs

示例5: SelectImageFromPicker

        async Task<WriteableBitmap> SelectImageFromPicker()
        {
            var picker = new FileOpenPicker();
            picker.ViewMode = PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");

            StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {

                ImageProperties imgProp = await file.Properties.GetImagePropertiesAsync();
                var savedPictureStream = await file.OpenAsync(FileAccessMode.Read);

                //set image properties and show the taken photo
                bitmap = new WriteableBitmap((int)imgProp.Width, (int)imgProp.Height);
                await bitmap.SetSourceAsync(savedPictureStream);
                bitmap.Invalidate();

                SaveImageAsync(file);

                return bitmap;
            }
            else return null;
        }
开发者ID:TomWalkerCodes,项目名称:HowToBBQ.Win10,代码行数:28,代码来源:BBQRecipeViewModel.cs

示例6: LoadIcon

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

            using (IRandomAccessStream fileStream = await imageFile.OpenAsync(FileAccessMode.Read))
            {
                WriteableBitmap bitmap = new WriteableBitmap(1, 1);
                await bitmap.SetSourceAsync(fileStream);
                return bitmap.ToBandIcon();
            }
        }
开发者ID:Theojim92,项目名称:SCP-with-O365,代码行数:11,代码来源:Tile.cs

示例7: GetWriteableBitmap

        private static async Task<WriteableBitmap> GetWriteableBitmap(Uri uri)
        {
            var imageFile = await StorageFile.GetFileFromApplicationUriAsync(uri);

            using (var fileStream = await imageFile.OpenAsync(FileAccessMode.Read))
            {
                var writeableBitmap = new WriteableBitmap(1, 1);
                await writeableBitmap.SetSourceAsync(fileStream);
                return writeableBitmap;
            }
        }
开发者ID:rpedersen,项目名称:microsoft-band-samples,代码行数:11,代码来源:UriExtensions.cs

示例8: GetPictureAsync

        public static async Task<WriteableBitmap> GetPictureAsync(StorageFile ImageFile)
        {

            using (IRandomAccessStream stream = await ImageFile.OpenAsync(FileAccessMode.Read))
            {
                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
                WriteableBitmap bmp = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);
                await bmp.SetSourceAsync(stream);
                return bmp;
            }
        }
开发者ID:aurora-lzzp,项目名称:Aurora-Weather,代码行数:11,代码来源:ImagingHelper.cs

示例9: GetThumbnail

        private async void GetThumbnail()
        {
            DeviceThumbnail thumb = await _information.GetGlyphThumbnailAsync();
            Stream s = thumb.AsStreamForRead();
            MemoryStream ms = new MemoryStream();
            await s.CopyToAsync(ms);
            ms.Seek(0, SeekOrigin.Begin);

            WriteableBitmap wb = new WriteableBitmap(1, 1);
            await wb.SetSourceAsync(ms.AsRandomAccessStream());
            _thumbnail = wb;
            OnPropertyChanged("Thumbnail");
        }
开发者ID:inthehand,项目名称:Charming,代码行数:13,代码来源:DeviceViewModel.cs

示例10: Quadraliteral

        public async void Quadraliteral(StorageFile file, IList<WF.Point> points)
        {
            var data = await FileIO.ReadBufferAsync(file);

            OpencvImageProcess opencv = new OpencvImageProcess();
            
            // create a stream from the file
            var ms = new InMemoryRandomAccessStream();
            var dw = new DataWriter(ms);
            dw.WriteBuffer(data);
            await dw.StoreAsync();
            ms.Seek(0);

            // find out how big the image is, don't need this if you already know
            var bm = new BitmapImage();
            await bm.SetSourceAsync(ms);

            // create a writable bitmap of the right size
            var wb = new WriteableBitmap(bm.PixelWidth, bm.PixelHeight);
            ms.Seek(0);

            // load the writable bitpamp from the stream
            await wb.SetSourceAsync(ms);

            Bitmap bmp = (Bitmap)wb;

            var wb1 = opencv.GetImageCorners(wb);

            wb1.Invalidate();
            //wb.Invalidate();
            // define quadrilateral's corners
            //List<IntPoint> corners = new List<IntPoint>();
            
            //foreach (var point in points)
            //{
            //    corners.Add(new IntPoint((int)point.X, (int)point.Y));
            //}
            
            //// create filter

            //var filter =
            //    new SimpleQuadrilateralTransformation(corners);
            
            //// apply the filter
            //Bitmap newImage = filter.Apply(bmp);

            //wb = (WriteableBitmap)newImage;

            var f = await this.WriteableBitmapToStorageFile(wb1, FileFormat.Jpeg);
        }
开发者ID:epustovit,项目名称:Scanner,代码行数:50,代码来源:ImageProccesing.cs

示例11: ReportPhoto

        public ReportPhoto(StorageFile file)
        {
            FilePath = file.Path;

            StorageItemThumbnail thumbnail = file.GetThumbnailAsync(ThumbnailMode.ListView).AsTask().Result;
            BitmapImage thumbnailImage = new BitmapImage();
            var ignore = thumbnailImage.SetSourceAsync(thumbnail);
            ThumbnailSource = thumbnailImage;

            StorageItemThumbnail imageAsThumbnail = file.GetScaledImageAsThumbnailAsync(ThumbnailMode.SingleItem).AsTask().Result;
            WriteableBitmap bitmap = new WriteableBitmap((int)imageAsThumbnail.OriginalWidth, (int)imageAsThumbnail.OriginalHeight);
            ignore = bitmap.SetSourceAsync(imageAsThumbnail);
            Bitmap = bitmap;
        }
开发者ID:KlubJagiellonski,项目名称:pola-windowsphone,代码行数:14,代码来源:ReportPhoto.cs

示例12: TakePhoto

        private async Task<StorageFile> TakePhoto()
        {
            StorageFile filestr = await USBCam.TakePhotoAsync("picture.jpg");
            Debug.WriteLine(string.Format("File name: {0}", filestr.Name));
            using (IRandomAccessStream myfileStream = await filestr.OpenAsync(FileAccessMode.Read))
            {
                WriteableBitmap bitmap = new WriteableBitmap(1, 1);

                await bitmap.SetSourceAsync(myfileStream);

                FacePhoto.Source = bitmap;
            }
            return filestr;
        }
开发者ID:Ellerbach,项目名称:BrickPi,代码行数:14,代码来源:FollowFace.cs

示例13: FromBase64

        public static async Task<ImageSource> FromBase64(string base64)
        {
            // read stream
            var bytes = Convert.FromBase64String(base64);
            var image = bytes.AsBuffer().AsStream().AsRandomAccessStream();

            // decode image
            var decoder = await BitmapDecoder.CreateAsync(image);
            image.Seek(0);

            // create bitmap
            var output = new WriteableBitmap((int) decoder.PixelHeight, (int) decoder.PixelWidth);
            await output.SetSourceAsync(image);
            return output;
        }
开发者ID:msk-one,项目名称:CollectorUWP,代码行数:15,代码来源:Base64Converter.cs

示例14: ConvertFromEncodedStream

        public async Task<object> ConvertFromEncodedStream(Stream encodedStream, int width, int height)
        {
            if (encodedStream == null)
                return null;

            var image = new WriteableBitmap(width, height);
            encodedStream.Seek(0, SeekOrigin.Begin);
            await image.SetSourceAsync(encodedStream.AsRandomAccessStream());

            return image;

            //var writeableImage = new WriteableBitmap(image.PixelWidth, image.PixelHeight);
            //image.SetSource(encodedStream.AsRandomAccessStream());
            //return writeableImage;
        }
开发者ID:Catrobat,项目名称:CatrobatForWindows,代码行数:15,代码来源:ImageSourceConversionServiceWindowsShared.cs

示例15: LoadImageAsync

		public async Task LoadImageAsync()
		{
			using (var stream = await file.OpenReadAsync())
			{
				WriteableBitmap bitmap = new WriteableBitmap(width, height);
				await bitmap.SetSourceAsync(stream);

				using (var buffer = bitmap.PixelBuffer.AsStream())
				{
					pixels = new Byte[4 * width * height];
					buffer.Read(pixels, 0, pixels.Length);
				}

				this.bitmap = bitmap;
			}
		}
开发者ID:robertiagar,项目名称:Pixelator,代码行数:16,代码来源:SimpleBitmap.cs


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