首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UWP RichEditBox InsertImage插入空白

UWP RichEditBox InsertImage插入空白
EN

Stack Overflow用户
提问于 2016-03-18 12:26:56
回答 1查看 683关注 0票数 0

我正在使用VisualStudioCommunity2015开发一个UWP。我创建了一个空白项目,添加了一个按钮和RichEditBox。我试图从本地资源中插入RichEditBox中的图像,但我只插入一个空白占位符(图像的所需大小)。不会抛出错误。

下面是代码:

代码语言:javascript
复制
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:

代码语言:javascript
复制
<Button Content="Insert image" Click="Button_Click"/>
<RichEditBox Name="box" Height="200"/>

构建StoreLogo.png的动作是"content",我试图将图像复制到输出目录中,这没有什么区别。

这里有什么问题吗?正确的方法是什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-21 11:49:01

但是,根据我的经验,我可以看到您的问题,常见的方法是使用StorageFile.OpenAsync获取IRandomAccessStream。并将其设置为ITextRange.InsertImage

例如:

代码语言:javascript
复制
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);

}

你可以试着用这种方法来解决这个问题。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36084393

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档