I'm currently writing a small image editing app for the Windows Store in which I'd like to make use of the share charm for edited images. As some apps do only accept StorageFiles and not Bitmaps (like the default Mail App) I'd like to offer the images in both ways as explained here: http://www.jeffblankenburg.com/2012/11/07/31-days-of-windows-8-day-7-share-contract However, I don't know how to create a StorageFile from a WrieableBitmap.
Perhaps you could help me completing my code below.
// Share Image
async void dtm_DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
DataRequestDeferral deferral = e.Request.GetDeferral();
DataPackage requestData = e.Request.Data;
requestData.Properties.Title = "My Image";
requestData.Properties.Description = "Created using a Windows Store App.";
// This stream is to create a bitmap image later
IRandomAccessStream stream = new InMemoryRandomAccessStream();
// Determin which type of BitmapEncoder we should create
Guid encoderId = BitmapEncoder.JpegEncoderId;
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(encoderId, stream);
Stream pixelStream = theImage.PixelBuffer.AsStream();
byte[] pixels = new byte[pixelStream.Length];
await pixelStream.ReadAsync(pixels, 0, pixels.Length);
encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)theImage.PixelWidth, (uint)theImage.PixelHeight, 96.0, 96.0, pixels);
requestData.SetBitmap(RandomAccessStreamReference.CreateFromStream(stream));
// What goes here?
StorageFile storageFileImage =
List<IStorageItem> files = new List<IStorageItem>();
files.Add(storageFileImage);
requestData.SetStorageItems(files);
requestData.Properties.Thumbnail = RandomAccessStreamReference.CreateFromStream(stream);
await encoder.FlushAsync();
deferral.Complete();
}