Avalonia:如何将PNG显示为图像?

发布于 2025-01-23 09:34:14 字数 318 浏览 4 评论 0原文

我还没有看到完成此操作的f#示例,或任何与我想做的足够相似的示例,因此希望这里的解决方案对他人有帮助。

我正在将Avalonia与F#一起构建简单的UI。我想在我的UI中包括图像,但是花了几个小时来查看文档和示例以及我所看到的一切外观都被过度复杂(也许真的很复杂?)。

我正在创建类似的图像:

let b = (Avalonia.Media.Imaging.Bitmap @"C:\Images\icon.png")
Image.create [
    Image.source b
]

这只是什么都没有显示。我在这里想念什么?

I haven't seen an F# example of accomplishing this, or any examples similar enough to what I am trying to do, so hopefully a solution here will be helpful to others.

I am using Avalonia with F# to build a simple UI. I want to include images in my UI, but have spent hours looking at documentation and examples and everything I've seen looks to be overcomplicated (maybe it really is just that complicated?).

I am creating an image like:

let b = (Avalonia.Media.Imaging.Bitmap @"C:\Images\icon.png")
Image.create [
    Image.source b
]

This just displays nothing. What am I missing here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懒猫 2025-01-30 09:34:14

要在上面的评论中添加更多详细信息,这是对我有用的:

let view =
    Component(fun ctx ->
        let b = new Avalonia.Media.Imaging.Bitmap("Small.png")
        Image.create [
            Image.source b
        ]
    )

”在此处输入图像描述”

To add more detail to my comment above, here's what works for me:

let view =
    Component(fun ctx ->
        let b = new Avalonia.Media.Imaging.Bitmap("Small.png")
        Image.create [
            Image.source b
        ]
    )

Result is:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文