我正在使用VisualStudioCommunity2015开发一个UWP。我创建了一个空白项目,添加了一个按钮和RichEditBox。我试图从本地资源中插入RichEditBox中的图像,但我只插入一个空白占位符(图像的所需大小)。不会抛出错误。
下面是代码:
private async void Button_Click(object sender, RoutedEventArgs e)
{
Uri imageUri = new Uri("ms-appx:///Assets/StoreLogo.png");
using (IRandomAccessStream ras = await RandomAccessStreamReference.CreateFromUri(imageUri).OpenReadAsync())
{
box.Document.Selection.InsertImage(64, 64, 0, VerticalCharacterAlignment.Baseline, "img", ras);
}
}以下是xaml:
<Button Content="Insert image" Click="Button_Click"/>
<RichEditBox Name="box" Height="200"/>构建StoreLogo.png的动作是"content",我试图将图像复制到输出目录中,这没有什么区别。
这里有什么问题吗?正确的方法是什么?
发布于 2016-03-21 11:49:01
但是,根据我的经验,我可以看到您的问题,常见的方法是使用StorageFile.OpenAsync获取IRandomAccessStream。并将其设置为ITextRange.InsertImage。
例如:
Uri imageUri = new Uri("ms-appx:///Assets/StoreLogo.png");
StorageFile imageFile = await StorageFile.GetFileFromApplicationUriAsync(imageUri);
using (IRandomAccessStream fileStream = await imageFile.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
box.Document.Selection.InsertImage(64, 64, 0, VerticalCharacterAlignment.Baseline, "img", fileStream);
}你可以试着用这种方法来解决这个问题。
https://stackoverflow.com/questions/36084393
复制相似问题