Windows 8 RandomAccessStreamReference的可写位图

Windows 8 RandomAccessStreamReference的可写位图,windows-8,windows-runtime,microsoft-metro,winrt-xaml,writablebitmap,Windows 8,Windows Runtime,Microsoft Metro,Winrt Xaml,Writablebitmap,我还有一个问题: 我使用WinRT XAML工具包(代码1)制作了一个屏幕截图 现在我想将此可写位图附加到电子邮件(代码2) 代码1 WriteableBitmap wb = null; var start = DateTime.Now; const int count = 1; for (int i = 0; i < count; i++) { wb = awa

我还有一个问题:

我使用WinRT XAML工具包(代码1)制作了一个屏幕截图

现在我想将此可写位图附加到电子邮件(代码2)

代码1

WriteableBitmap wb = null;
            var start = DateTime.Now;
            const int count = 1;
            for (int i = 0; i < count; i++)
            {
                wb = await WriteableBitmapRenderExtensions.Render(this);
            }
            var end = DateTime.Now;
            var duration = end - start;
            var renderInS = duration.TotalMilliseconds / count;
            if (renderInS > 0)
            {
                test.Source = wb;
                // HERE MUST BE CODE INCLUDED
            }
WriteableBitmap wb=null;
var start=DateTime.Now;
常数int计数=1;
for(int i=0;i0)
{
test.Source=wb;
//这里必须包含代码
}
代码2

DataPackage requestData = request.Data;
            requestData.Properties.Title = TitleInputBox.Text;
            requestData.Properties.Description = DescriptionInputBox.Text; // The description is optional.

            // It's recommended to use both SetBitmap and SetStorageItems for sharing a single image
            // since the target app may only support one or the other.

            List<IStorageItem> imageItems = new List<IStorageItem>();
            imageItems.Add(this.imageFile);
            requestData.SetStorageItems(imageItems);

            RandomAccessStreamReference imageStreamRef = RandomAccessStreamReference.CreateFromFile(this.imageFile);
            requestData.Properties.Thumbnail = imageStreamRef;
            requestData.SetBitmap(imageStreamRef);
            succeeded = true;
DataPackage requestData=request.Data;
requestData.Properties.Title=TitleInputBox.Text;
requestData.Properties.Description=DescriptionInputBox.Text;//描述是可选的。
//建议使用SetBitmap和SetStorageItems来共享单个图像
//因为目标应用程序可能只支持其中一个。
List imageItems=新列表();
imageItems.Add(此.imageFile);
requestData.SetStorage项目(imageItems);
RandomAccessStreamReference imageStreamRef=RandomAccessStreamReference.CreateFromFile(this.imageFile);
requestData.Properties.Thumbnail=imageStreamRef;
requestData.SetBitmap(imageStreamRef);
成功=真;
这意味着我需要先将图像保存到本地存储器,然后读取并附加它

问题:

1)如何将可写位图保存到应用程序本地存储?


2)也许有一种方法不保存图像以附加它?更新

使用&

MemoryStream stream=newmemoryStream(MyWriteableBitmap.ToByteArray());
var randomAccessStream=新的MemoryRandomAccessStream(流);
DataPackage requestData=args.Request.Data;
RandomAccessStreamReference imageStreamRef=RandomAccessStreamReference.CreateFromStream(randomAccessStream);

尝试将WriteableBitmap保存到StorageFile

专用异步任务WriteableBitMapToStorage文件(WriteableBitmap WriteableBitmap)
{
var picker=new FileSavePicker();
添加(“JPEG图像”,新字符串[]{.jpg”});
StorageFile file=wait picker.PickSaveFileAsync();
if(file!=null&&writeableBitmap!=null)
{
使用(irandomaccesstream=await file.OpenAsync(FileAccessMode.ReadWrite))
{
BitmapEncoder编码器=等待BitmapEncoder.CreateAsync(
BitmapEncoder.JpegEncoderId,流);
Stream pixelStream=writeableBitmap.PixelBuffer.AsStream();
字节[]像素=新字节[pixelStream.Length];
等待pixelStream.ReadAsync(像素,0,像素,长度);
编码器.SetPixelData(BitmapPixelFormat.Bgra8,BitmapAlphaMode.Ignore,
(uint)writeableBitmap.PixelWidth,(uint)writeableBitmap.PixelHeight,96.0,96.0,像素);
等待编码器。FlushAsync();
}
返回文件;
}
其他的
{
返回null;
}
}

是的,我已经拿到了。但邮件似乎不允许发送图像或附件,对吗?因为它只允许我选择-SkyDriweMail只允许附件或位图和/或文本。嗨,伙计。。。请问,是否可以将流转换为IStorageItem?(请用Javascript)。我想将此文件与其他文件一起附加,因此使用方法setStorage Items:)