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


C# WriteableBitmap.FromStream方法代码示例

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


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

示例1: ChooseReferenceImage

        private async Task ChooseReferenceImage()
        {
            FileOpenPicker openPicker = new FileOpenPicker();
            openPicker.ViewMode = PickerViewMode.Thumbnail;
            openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".png");

            StorageFile file = await openPicker.PickSingleFileAsync();
            if (file != null)
            {
                try
                {
                    var img = new BitmapImage();


                    using (Windows.Storage.Streams.IRandomAccessStream fileStream =
                        await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                    {
                        // Set the image source to the selected bitmap.
                        var refImage =
                            new BitmapImage();
                        refImage.CreateOptions = BitmapCreateOptions.IgnoreImageCache;


                        refImage.SetSource(fileStream);
                        RefImage = refImage;

                        ReferenceImage = new WriteableBitmap(refImage.PixelWidth, refImage.PixelHeight);
                        //fileStream.Seek(0);
                        ReferenceImage = await ReferenceImage.FromStream(fileStream);

                        ChooseThemeVisibility = Visibility.Visible;
                    }
                }
                catch (Exception)
                {
                    var messageDialog =
                        new MessageDialog("Please select an image. Any other file-type is not supported.");
                    await messageDialog.ShowAsync();
                }
            }
        }
开发者ID:Injac,项目名称:Universal-Asset-Creator,代码行数:44,代码来源:MainViewModel.cs

示例2: CreateBluredCoverArt

 private async void CreateBluredCoverArt(string coverArt)
 {
     var writeableBitmap = new WriteableBitmap(1, 1);
     var streamTask = coverArt == CoverArtPlaceholderLarge ? GetStreamFromFile(coverArt) : GetStreamFromUri(coverArt);
     using (var stream = await streamTask)
     {
         writeableBitmap = await writeableBitmap.FromStream(stream);
     }
     var bluredImage = writeableBitmap.Convolute(Gaussian11X11Kernel);
     BluredCoverArt = bluredImage;
 }
开发者ID:pirvudoru,项目名称:SubSonic8,代码行数:11,代码来源:PlaybackViewModel.cs

示例3: GetWriteableBitmap

        private async Task<BitmapSource> GetWriteableBitmap()
        {
            var width = (int)this.Width;
            var height = width;
            WriteableBitmap writeableBitmap = null;
            string cacheFileName = string.Format("{0}.{1}", this.CacheName, ImageExtension);
            var storageFile = await Windows.Storage.ApplicationData.Current.LocalFolder.TryGetItemAsync(cacheFileName) as StorageFile;
            if (storageFile != null)
            {
                writeableBitmap = await new WriteableBitmap(width, height).LoadAsync(storageFile);
            }
            else
            {
                try
                {
                    var innerWidth = width / 2;
                    var innerHeight = innerWidth;
                    writeableBitmap = new WriteableBitmap(width, height);
                    int index = 0;
                    foreach (Uri uri in this.m_uriCollection)
                    {
                        try
                        {
                            var randomAccessStreamReference = RandomAccessStreamReference.CreateFromUri(uri);
                            using (IRandomAccessStream randomAccessStream = await randomAccessStreamReference.OpenReadAsync())
                            {
                                if (randomAccessStream != null)
                                {
                                    //We initialize the bitmap with height and width, but the actual size will be reset after the FromStream method!
                                    WriteableBitmap innerImage = new WriteableBitmap(innerWidth, innerHeight);
                                    innerImage = await innerImage.FromStream(randomAccessStream);

                                    int xPosition = 0;
                                    int yPosition = 0;

                                    if (index == 1 || index == 2)
                                    {
                                        xPosition = xPosition + innerWidth;
                                    }
                                    if (index == 2 || index == 3)
                                    {
                                        yPosition = yPosition + innerHeight;
                                    }

                                    writeableBitmap.Blit(
                                        new Rect()
                                        {
                                            Height = innerHeight,
                                            Width = innerWidth,
                                            X = xPosition,
                                            Y = yPosition
                                        },
                                            innerImage,
                                            new Rect()
                                            {
                                                Height = innerImage.PixelHeight,
                                                Width = innerImage.PixelWidth,
                                                X = 0,
                                                Y = 0
                                            }, WriteableBitmapExtensions.BlendMode.Additive);
                                }
                                index++;
                            }
                        }
                        catch(Exception)
                        { }
                    }
                    await writeableBitmap.SaveToFile(Windows.Storage.ApplicationData.Current.LocalFolder, cacheFileName, CreationCollisionOption.ReplaceExisting);
                }
                catch (Exception)
                {
                }
            }
            return writeableBitmap;
        }
开发者ID:uwe-e,项目名称:BSE.Tunes,代码行数:75,代码来源:WriteableImage.cs

示例4: RecievedFiles

        public async void RecievedFiles(IEnumerable<object> files)
        {
            var fileArray = files as object[] ?? files.ToArray();

            if (fileArray.Length == 0)
            {
                ServiceLocator.DispatcherService.RunOnMainThread(() =>
                    ServiceLocator.NavigationService.NavigateTo<NewLookSourceSelectionViewModel>());
            }
            StorageFile file = (StorageFile)fileArray[0];

            var fileStream = await file.OpenReadAsync();
            var memoryStream = new MemoryStream();
            fileStream.AsStreamForRead().CopyTo(memoryStream);
            memoryStream.Seek(0, SeekOrigin.Begin);

            BitmapImage imagetobind = new BitmapImage();
            await imagetobind.SetSourceAsync(memoryStream.AsRandomAccessStream());

            WriteableBitmap writeableBitmap = new WriteableBitmap(imagetobind.PixelWidth, imagetobind.PixelHeight);
            await writeableBitmap.FromStream(memoryStream.AsRandomAccessStream());
            memoryStream.Seek(0, SeekOrigin.Begin);
            PortableImage portableImage = new PortableImage(writeableBitmap)
            {
                Width = writeableBitmap.PixelWidth,
                Height = writeableBitmap.PixelHeight,
                EncodedData = memoryStream
            };

            if (_lookToEdit == null)
            {
                if (portableImage != null) // TODO: check if image is ok
                {
                    var message = new GenericMessage<PortableImage>(portableImage);
                    Messenger.Default.Send(message, ViewModelMessagingToken.LookImageListener);

                    ServiceLocator.DispatcherService.RunOnMainThread(() =>
                        ServiceLocator.NavigationService.NavigateTo<LookNameChooserViewModel>());
                }
                else
                {
                    ServiceLocator.NotifictionService.ShowMessageBox(AppResourcesHelper.Get("Editor_MessageBoxWrongImageFormatHeader"),
                        AppResourcesHelper.Get("Editor_MessageBoxWrongImageFormatText"), delegate { /* no action */ }, MessageBoxOptions.Ok);
                }
            }
            else
            {
                using (var storage = StorageSystem.GetStorage())
                {
                    var filePath = Path.Combine(_program.BasePath,
                        StorageConstants.ProgramLooksPath, _lookToEdit.FileName);

                    await storage.DeleteImageAsync(filePath);

                    var lookFileStream = await storage.OpenFileAsync(filePath,
                        StorageFileMode.Create, StorageFileAccess.Write);

                    await (await file.OpenReadAsync()).AsStream().CopyToAsync(lookFileStream);

                    lookFileStream.Dispose();

                    await storage.TryCreateThumbnailAsync(filePath);

                    _lookToEdit.Image = await storage.LoadImageThumbnailAsync(filePath);
                }

                _lookToEdit = null;
            }
        }
开发者ID:Catrobat,项目名称:CatrobatForWindows,代码行数:69,代码来源:PictureServiceWindowsShared.cs

示例5: GetBitmapSource

		public async Task<BitmapSource> GetBitmapSource(object bitmapSource, string cacheName, int width, bool asThumbnail = false)
		{
			var height = width;
			WriteableBitmap writeableBitmap = null;
			ObservableCollection<Uri> uriSource = bitmapSource as ObservableCollection<Uri>;
			if (!string.IsNullOrEmpty(cacheName) && uriSource != null)
			{
				try
				{
					cacheName = asThumbnail ? cacheName + ThumbnailPart : cacheName;
					string cacheFileName = string.Format("{0}.{1}", cacheName, ImageExtension);
					var storageFolder = await LocalStorage.GetImageFolderAsync();
					var storageFile = await storageFolder.TryGetItemAsync(cacheFileName) as StorageFile;
					if (storageFile != null)
					{
						writeableBitmap = await new WriteableBitmap(width, height).LoadAsync(storageFile);
					}

					var innerWidth = width / 2;
					var innerHeight = innerWidth;
					writeableBitmap = new WriteableBitmap(width, height);
					int index = 0;
					foreach (Uri uri in uriSource)
					{
						try
						{
							var randomAccessStreamReference = RandomAccessStreamReference.CreateFromUri(uri);
							using (IRandomAccessStream randomAccessStream = await randomAccessStreamReference.OpenReadAsync())
							{
								if (randomAccessStream != null)
								{
									//We initialize the bitmap with height and width, but the actual size will be reset after the FromStream method!
									WriteableBitmap innerImage = new WriteableBitmap(innerWidth, innerHeight);
									innerImage = await innerImage.FromStream(randomAccessStream);

									int xPosition = 0;
									int yPosition = 0;

									if (index == 1 || index == 2)
									{
										xPosition = xPosition + innerWidth;
									}
									if (index == 1 || index == 3)
									{
										yPosition = yPosition + innerHeight;
									}

									writeableBitmap.Blit(
										new Rect()
										{
											Height = innerHeight,
											Width = innerWidth,
											X = xPosition,
											Y = yPosition
										},
											innerImage,
											new Rect()
											{
												Height = innerImage.PixelHeight,
												Width = innerImage.PixelWidth,
												X = 0,
												Y = 0
											}, WriteableBitmapExtensions.BlendMode.Additive);
								}
								index++;
							}
						}
						catch (Exception)
						{ }
					}
					await writeableBitmap.SaveToFile(storageFolder, cacheFileName, CreationCollisionOption.ReplaceExisting);
				}
				catch (Exception)
				{
				}
			}
			return writeableBitmap;
		}
开发者ID:uwe-e,项目名称:BSE.Tunes,代码行数:78,代码来源:CacheableBitmapService.cs

示例6: CreateBluredCoverArt

 private async void CreateBluredCoverArt(string coverArt)
 {
     var dispatcher = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher;
     await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
             {
                 var writeableBitmap = new WriteableBitmap(1, 1);
                 var streamTask = coverArt == CoverArtPlaceholderLarge
                                      ? GetStreamFromFile(coverArt)
                                      : GetStreamFromUri(coverArt);
                 using (var stream = await streamTask)
                 {
                     writeableBitmap = await writeableBitmap.FromStream(stream);
                     var bluredImage = writeableBitmap.Convolute(Gaussian11X11Kernel);
                     BluredCoverArt = bluredImage;
                 }
             });
 }
开发者ID:valentingovo,项目名称:SubSonic8,代码行数:17,代码来源:PlaybackViewModel.cs


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