rust - 在使用 cargo-bundle 构建 .app 后,如何从不断变化的路径环境中加载图像?
问题描述
我正在使用cargo-bundle为使用 fltk-rs 构建的 Rust 应用程序创建一个 .app 包。应用程序中有资产,例如图像。在我开发时,访问这些资产没有问题。
main.rs:
let mut my_img = SharedImage::load("imgs/smiley.png").unwrap();
.
├── Cargo.lock
├── Cargo.toml
├── app_icon_design.psd
├── imgs
│ └── smiley.PNG <--get this image
├── src
│ ├── app_icon.png
│ ├── app_icon@2x.png
│ ├── icon32x32.png
│ └── main.rs
└── target
├── CACHEDIR.TAG
├── debug
└── release
然后我捆绑到一个 .app,cargo build --release
它在我的 .app 中提供了以下目录结构:
.
├── Info.plist
├── MacOS
│ └── build_to_app_bundle <--my executable
└── Resources
└── imgs
└── smiley.PNG<--get this image now
现在我的应用程序需要从/Resources
文件夹中获取图像文件:
println!("my resources folder is: {:?}", std::env::current_exe().unwrap().parent().unwrap().join(Path::new("Resources")));
let my_resources_path = std::env::current_exe().unwrap().parent().unwrap().join(Path::new("Resources"));
我怎样才能做到每次我想从路径加载图像时都不需要显式引用该Resources
值?
解决方案
推荐阅读
- java - FINE 日志记录 org.postgresql.jdbc.PgConnection setAutoCommit = false
- security - 将 Power BI Desktop 连接到 Azure SQL 的最安全方式
- c# - C#:如何从 Sharepoint Teamsite 站点下载和上传文件
- java - 许多错误尝试从空对象引用上的“android.os.Handler android.view.View$AttachInfo.mHandler”字段读取
- gradle - 如何将应用的 gradle 脚本的执行推迟/延迟到构建脚本的最后一个
- arduino - 通过 ESP8266 上的 UDP 广播消息
- haskell - 在 Haskell 中的函数之间共享变量的惯用方式?
- spring-boot - 在 Spring 安全中使用证书进行相互身份验证
- node.js - 在一个 GIT 存储库中,是否可以使用 nodejs 将文件添加/提交/推送到另一个 GIT 存储库
- python - 使用更改参数调用 python 程序的 Shell 脚本