コード例 #1
0
        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();
                }
            }
        }
コード例 #2
0
 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;
 }
コード例 #3
0
ファイル: WriteableImage.cs プロジェクト: uwe-e/BSE.Tunes
        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;
        }
コード例 #4
0
        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;
            }
        }
コード例 #5
0
		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;
		}
コード例 #6
0
 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;
                 }
             });
 }