I'd like to be able to take an existing photo and set it as the album artwork.
I can use GetThumbnailAsync
to give me a thumbnail and GetOutputStream
to get the thumbnails output stream. Unfortunately, it's not writeable.
How might I set the album artwork (or any thumbnail) on an item in a Win8 C# application?
Current (non-working) code. It dies when the outStream is flushed with an Access Denied Error
FileOpenPicker fileopenpicker = new FileOpenPicker();
fileopenpicker.FileTypeFilter.Add(".jpg");
fileopenpicker.FileTypeFilter.Add(".png");
fileopenpicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;// | PickerLocationId.DocumentsLibrary | PickerLocationId.PicturesLibrary | PickerLocationId.MusicLibrary;
var singlefileoperation = await fileopenpicker.PickSingleFileAsync();
var read = await singlefileoperation.OpenAsync(FileAccessMode.Read);
StorageFile replay = currentlyPlaying;
TimeSpan pos = ME.Position;
ME.Stop();
//curren
StorageItemThumbnail storageItemThumbnail = await currentlyPlaying.GetThumbnailAsync(ThumbnailMode.SingleItem);
IOutputStream inputStreamAt = storageItemThumbnail.GetOutputStreamAt(0);
Stream outStream = inputStreamAt.AsStreamForWrite();
var inStreamAt = read.GetInputStreamAt(0);
var inStream = inStreamAt.AsStreamForRead();
await inStream.CopyToAsync(outStream);
await outStream.FlushAsync();
outStream.Dispose();
inStream.Dispose();
inStreamAt.Dispose();