首页 > 解决方案 > 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");
        }

    }

标签: widthbitmapimage

解决方案


推荐阅读