width - c# BitmapImage Width 和 Height 等于 1
问题描述
有人可以帮我使用 BitmapImage 吗?
我在 wpf 项目中使用 BitmapImage。当我将 wpf 项目设置为启动项目并运行它时,代码工作正常,但是当我从 winform 项目代码启动 wpf exe 时,位图图像的宽度和高度为 1。
代码示例如下:
public async Task Open(string path)
{
string strpath = System.AppDomain.CurrentDomain.BaseDirectory + path;
strpath = @"F:\test\Meteorology\Meteorology\bin\Debug\pic\56778.JPG";
if (System.IO.File.Exists(strpath))
{
Image = null;
RaisePropertyChanged("Image");
IsLoading = true;
RaisePropertyChanged("IsLoading");
await Task.Factory.StartNew(() =>
{
Image = new BitmapImage();
Image.BeginInit();
Image.CacheOption = BitmapCacheOption.OnLoad;
Image.UriSource = new Uri(strpath);
Image.EndInit();
Image.Freeze();
});
if (Math.Abs(Image.Width / Image.Height - 2) > 0.001)
WarningMessage("Warning", "The opened image is not equirectangular (2:1)! Rendering may be improper.");
RecentImageManager.AddAndSave(path);
IsLoading = false; RaisePropertyChanged("IsLoading");
RaisePropertyChanged("Image");
}
}
解决方案
推荐阅读
- symfony - 如何在 Symfony 4 中启用生产模式?
- javascript - JavaScript 正则表达式。将html解析为文本
- opencv - opencv solvePnP,所有轴看起来都不错,除了 Y
- javascript - 计算前端不安全的价格?
- kubernetes - Kubernetes RBAC - 禁止尝试授予额外权限
- python - 使用 Selenium 在 python 中的 WebScraping 问题
- c++ - 使用 std::vector 迭代器和调整大小/保留的奇怪/有趣的行为
- bash - shell脚本中的命令在线参数
- lambda - “无法转换对象 keras”:如何正确实现这一层?
- abap - 比 CL_GUI_BTFEDITOR 性能更高的富文本控件?