Best way to export image / animation from GUI, including colorbar

4 次查看(过去 30 天)
Hi, am am trying to export a graphics file from a uifigure. The plot has several layers and elements, and also features a colorbar outside of the axes. I tried getframe(gcf) and getframe(gca), both are not suitable (one does not include the colorbar, the other does include the whole uifigure, see attachments).
In the past, I was copying all elements from the uifigure to a new, invisible figure using copyobj, then using getframe(gca) to get a clean image that includes the colorbar. But this involves a lot of extra code to deal with all the details, and this is prone to errors I think.
I wonder if there are good ways to achieve this?
My GUI does not only display still images, but also image sequences. Hence, I additionally want to write videofiles directly from this Matlab GUI. So I think exportfig is not really an option?
Thanks for your input!
  2 个评论
Mario Malic
Mario Malic 2023-11-13
I would suggest to output an image, open it and remove the portion which you don't want to be in the picture. By this, I mean to "crop" the part you want to save.
William Thielicke
William Thielicke 2023-11-13
Hi, this is something that I also consider, but it involves an additional file read and file write, which is slow for animations....

请先登录,再进行评论。

回答(1 个)

William Thielicke
William Thielicke 2023-11-13
I think I am close to a good solution:
The function that does all the plotting / imagesc / scatter in the uifigure got an additional input argument: The target axis. Now I can select if the graphics are plotted in the uifigure, or in a new, hidden figure. This hidden figure is a regular figure without ui elements. Therefore I can export it in a simple way with getframe(target_axis).
  2 个评论
William Thielicke
William Thielicke 2023-11-26
Unfortunately, the figure cannot be hidden, because then all of Matlabs plotting doesn't work properly. WHAT A MESS. Incredible that I am spending days on finding out how to plot figures properly....
Viktor Janzen
Viktor Janzen 2024-4-9
I have a similar problem. Because I am offering my uifigure within a webapp, it is not possible to open a second figure (visible or hidden), beacuse Web Apps do not support multi-window application.
I had a solution with getframe. But the big problem with getframe is that it makes a snapshot from the whle uiffigure, considering also all hidden UI components and then reduces the frame to the axes, which is the input argument. For my animation it takes about 4 seconds per frame.
I tested with deleting many hidden UI components. Then it takes half of the time.
You can also put the uifigure as input argument. Then a video from the whole app is made.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品


版本

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by