【问题标题】:Creating a "Rotate 90 degrees" button in MATLAB App Designer在 MATLAB App Designer 中创建“旋转 90 度”按钮
【发布时间】:2021-03-17 06:44:15
【问题描述】:

我正在尝试在 MATLAB 中使用 App Designer 制作一个简单的 GUI。我想要一个名为“Rotate 90”的按钮,每次按下它都会将图形旋转 90 度。我设法做的是只旋转一次,但是我有一个明显的问题,当再次按下时,它会再次旋转原始图片,而不是刚刚生成的新图片。

UIAXes 是我之前在其中显示图形的轴。 在回调之前我有以下属性:

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure            matlab.ui.Figure
        OpenimageButton     matlab.ui.control.Button
        TextArea            matlab.ui.control.TextArea
        DropDownHistogram   matlab.ui.control.DropDown
        DropDownProperties  matlab.ui.control.DropDown
        Rotate90Button      matlab.ui.control.Button
        Rotate180Button     matlab.ui.control.Button
        UIAxes              matlab.ui.control.UIAxes
        UIAxes_2            matlab.ui.control.UIAxes
    end

    
    properties (Access = private)
        oldpath = addpath(genpath('/Libraries/')) % Load libraries
        ImageFile; % Image loaded
        handlehistogram;
        fullname;
        degrees;
    end

回调函数如下:

        % Button pushed function: Rotate90Button
        function Rotate90ButtonPushed(app, event)
            
            image90 = app.ImageFile;
            
            rotated90 = imrotate(image90, 90);
            imagesc(app.UIAxes, rotated90);  

        end

【问题讨论】:

    标签: matlab user-interface button rotation


    【解决方案1】:

    如果有人感兴趣,我就是这样解决的:

    我添加了一个名为 rotateImg 的属性

        properties (Access = private)
            oldpath = addpath(genpath('/Libraries/')) % Load libraries
            ImageFile; % Image loaded
            handlehistogram;
            fullname;
            filename;
            degrees;
            rotatedImg;
        end
    

    我在回调函数中写了这个:

            % Button pushed function: Rotate90Button
            function Rotate90ButtonPushed(app, event)
             
                app.rotatedImg = imrotate(app.rotatedImg, 90);
              
                imagesc(app.UIAxes, app.rotatedImg);  
    
            end
    

    【讨论】:

      猜你喜欢
      • 2015-02-08
      • 2013-02-13
      • 2014-07-11
      • 1970-01-01
      • 2018-03-21
      • 1970-01-01
      • 1970-01-01
      • 2021-05-24
      • 2011-03-22
      相关资源
      最近更新 更多