c#BitmapImage宽度和高度等于1

时间:2018-04-26 09:58:36

标签: width bitmapimage

有人可以帮我使用BitmapImage吗?

我在wpf项目中使用BitmapImage。当我设置wpf项目是启动项目,并运行它时代码工作正常,但是当我从winform项目代码启动wpf exe时,bitmapimage的宽度和高度为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");
        }

    }

0 个答案:

没有答案