Search code examples
matlabrefreshsave-as

MATLAB 2014b getframe causes UI to 'blank'


I am currently developing a complex MATLAB application. I am trying to save figures (created within its UI) by using the getframe function. This works fine, and saves the figure as intended. However, the UI 'blanks' after every use. The window remains but becomes a uniform white rectangle. Mousing over features in the UI makes them appear again (like a fog-of-war). Adding a refresh statement did not help.

Why does this happen? How do i make it stop?

Irritatingly this doesn't happen in 2018a, but the code is in 2014b, which is problematic (something I discovered after being pleased at my cool fix :( ).

Unfortunately posting code is not feasible because I do not have permission to share it.


Solution

  • OK after much research I've been unable to find a direct solution. But I have implemented an indirect solution.

    refresh
    

    was not working so I implemented a manual, forced redraw. I.e. I jitter the screen after getframe by 1 pixel, which redraws the window.

    figpos = fig.Position;    
    jitter = figpos;
    jitter(3) = jitter(3) + 1;
    jitter(4) = jitter(4) + 1;
    set(fig,'Position',jitter);
    set(fig,'Position',figpos);
    

    It's probably unnecessary to expand, and contract, both the width and height of the window, but it does the job fine.