Exportapp error in saving entire app designer GUI
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I am trying to use the exportapp function to save the entire app designer GUI but I get this error:
Error using exportapp
Specified handle is not valid for export.
Any idea why? can I change the DPI of the image?
Code:
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
PlotGraphButton matlab.ui.control.Button
SaveGUIButton matlab.ui.control.Button
UIAxes matlab.ui.control.UIAxes
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: SaveGUIButton
function SaveGUIButtonPushed(app, event)
filter = {'*.jpg';'*.png';'*.tif';'*.pdf'};
[filename,filepath] = uiputfile(filter);
if ischar(filename)
exportapp(app.UIAxes,[filepath filename]);
end
end
% Button pushed function: PlotGraphButton
function PlotGraphButtonPushed(app, event)
x = linspace(0,2*pi,100);
y = sin(x);
plot(app.UIAxes,x,y)
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'MATLAB App';
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Title')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
zlabel(app.UIAxes, 'Z')
app.UIAxes.Position = [185 185 306 243];
% Create SaveGUIButton
app.SaveGUIButton = uibutton(app.UIFigure, 'push');
app.SaveGUIButton.ButtonPushedFcn = createCallbackFcn(app, @SaveGUIButtonPushed, true);
app.SaveGUIButton.Position = [418 73 102 47];
app.SaveGUIButton.Text = 'Save GUI';
% Create PlotGraphButton
app.PlotGraphButton = uibutton(app.UIFigure, 'push');
app.PlotGraphButton.ButtonPushedFcn = createCallbackFcn(app, @PlotGraphButtonPushed, true);
app.PlotGraphButton.Position = [163 73 125 47];
app.PlotGraphButton.Text = 'Plot Graph';
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = app1
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
0 commentaires
Réponses (1)
Simon Chan
le 9 Oct 2022
It support figure object and hence you should use:
exportapp(app.UIFigure,[filepath filename]);
4 commentaires
Simon Chan
le 10 Oct 2022
I just try to save a figure using exportgraphics by using TIF format and the resolution can be 500 DPI.
On the other hand, you may try to use function print
print(app.UIFigure,'-djpeg','-r500','filename')
Voir également
Catégories
En savoir plus sur Printing and Saving dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!