在caliburn.micro Wpf MVVM中获取图像内的坐标

问题描述

我陷入了一个问题。我从BitmapImage类加载图像。实际上,我从DICOM文件中获得的图像比将其转换为Bitmapimage并使用tag显示的图像更重要。我想生成一个事件,并且要使用两次鼠标左键单击来获得坐标。我知道我无法在视图模型中使用事件违反MVVM结构。在这里,我给出我的代码以更好地理解它。 <Image Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="4" x:Name="DIIMG2" ></Image> 现在我给viewmodel C#代码

 public void Getimage()
    {
        //CurrentIndex = 0;
        // Select WPF based imaging
        ImageManager.SetImplementation(WPFImageManager.Instance);

        // Loading DICOM file
        var dicomFile = DicomFile.Open(FilePath);

        // Render Image to JPEG 
        var dicomImage = new DicomImage(FilePath);


        NumberOfFrames = dicomImage.NumberOfFrames;

        //based on Number of Frames Increase and Decrease Button shows
      
        //Set slider's max value
        AllFrames = Enumerable.Range(0,NumberOfFrames)
            .Select(frame => dicomImage.RenderImage(frame).As<WriteableBitmap>());

        // CurrentFrame = dicomImage.RenderImage(CurrentIndex).As<WriteableBitmap>();//This code Has Problem as currentIndex has prior Value
        CurrentFrame = dicomImage.RenderImage(0).As<WriteableBitmap>();//here I use (0) as (CurrentIndex) has prior value
        MemoryStream outStream;


        using (outStream = new MemoryStream())
        {
            BitmapEncoder enc = new BmpBitmapEncoder();
            enc.Frames.Add(BitmapFrame.Create((BitmapSource)CurrentFrame));
            enc.Save(outStream);
            DIIMG_BITMAPIMAGE = new System.Drawing.Bitmap(outStream);
            Convert_BitMap_Bitimage(DIIMG_BITMAPIMAGE);
        }
        DIIMG3 = DIIMG2;

        
    }

这是我将代码转换为Bitmap并转换为Bitmapimage以显示为图像的代码

 public void Convert_BitMap_Bitimage(Bitmap bitImg)
    {
        using (MemoryStream memory = new MemoryStream())
        {
            bitImg.Save(memory,System.Drawing.Imaging.ImageFormat.Bmp);
            memory.Position = 0;
            BitmapImage bitmapimage = new BitmapImage();
            bitmapimage.BeginInit();
            bitmapimage.StreamSource = memory;
            bitmapimage.CacheOption = BitmapCacheOption.OnLoad;
            bitmapimage.EndInit();
            DIIMG2 = bitmapimage;
            //return bitmapimage;
        }
    }

这是我的财产 公共诠释NumberOfFrames { 得到{return num_offrames; } 组 { num_offrames =值; NotifyOfPropertyChange(()=> NumberOfFrames); } }

    public int CurrentIndex
    {
        get { return cur_Frame_indx; }
        set
        {
            cur_Frame_indx = value;
            NotifyOfPropertyChange(() => CurrentIndex);

            //Change Frame 
            CurrentFrame = AllFrames.ElementAtOrDefault(CurrentIndex);
        }
    }


    public System.Drawing.Bitmap DIIMG_BITMAPIMAGE
    {
        get
        {
            return diImg;
        }
        set
        {
            diImg = value;
            NotifyOfPropertyChange(() => DIIMG_BITMAPIMAGE);
        }
    }

    // System.Windows.Media.Imaging.BitmapImage diimg2;

    public System.Windows.Media.Imaging.BitmapImage DIIMG2
    {
        get
        {
            return diimg2;
        }
        set
        {
            diimg2 = value;
            NotifyOfPropertyChange(() => DIIMG2);
        }
    }
    public System.Windows.Media.Imaging.BitmapImage DIIMG3
    {
        get
        {
            return diimg3;
        }
        set
        {
            diimg3 = value;
            NotifyOfPropertyChange(() => DIIMG2);
        }
    }
    public WriteableBitmap CurrentFrame
    {
        get
        {
            return _currentFrame;
        }
        set
        {
            _currentFrame = value;
            NotifyOfPropertyChange(() => CurrentFrame);
        }
    }

请帮助我如何使用“鼠标单击”从图像获取坐标。预先感谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...