Azzera filtri
Azzera filtri

How to save app.Tab as image (.png for example)

21 visualizzazioni (ultimi 30 giorni)
FD
FD il 25 Lug 2024
Commentato: FD il 31 Lug 2024 alle 5:37
I have five app.Tabs.
First Tab is named app.Cooling.
Content of this app.Cooling:
1) picture of cooling system
2) app. fields with temperature value
3) plots of 4 diagrams (app.UIAxes) and legends
This app.Cooling I want to save as image (.png).
I try exportgraphics, saveas etc., but it doesn't work.
Schema of my example:
How I can save this whole tab as image?

Risposta accettata

Avni Agrawal
Avni Agrawal il 25 Lug 2024
Hi @FD,
I understand that you are trying to capture a snapshot of a specific tab in MATLAB App Designer, including all its contents like images, fields, and plots, you can use a workaround that involves capturing the entire figure and then cropping the relevant section corresponding to the tab.
Below is an example code snippet that demonstrates how to achieve this:
%call this function by passing appropriate tab needed to be captured and file name.
function takeSnapshot(app, tab, filename)
% Ensure the tab is selected
app.TabGroup.SelectedTab = tab;
% Pause to ensure the UI is fully rendered
pause(1);
% Capture the entire figure
frame = getframe(app.UIFigure);
img = frame.cdata;
% Save the image
imwrite(img, filename);
disp(['Snapshot saved as ', filename]);
end
I hope this helps!
  5 Commenti
Avni Agrawal
Avni Agrawal il 30 Lug 2024 alle 21:11
Hi,
To capture all five tabs at once, here is a code snippet with an example of capturing two tabs:
% Select the first tab and capture its content
app.TabGroup.SelectedTab = app.Tab;
pause(1);
frame = getframe(app.UIFigure);
img = frame.cdata;
% Save the image
imwrite(img, 'test1.png');
% Select the second tab and capture its content
app.TabGroup.SelectedTab = app.Tab2;
pause(1);
frame = getframe(app.UIFigure);
img = frame.cdata;
% Save the image
imwrite(img, 'test2.png');
In this example, `app.Tab` and `app.Tab2` are two tabs from the Tab group. Please rename the tabs according to your code.
I hope this helps!
FD
FD il 31 Lug 2024 alle 5:37
This works perfectly :-)
Very big thank You!!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Printing and Saving in Help Center e File Exchange

Prodotti


Release

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by