Exportapp error in saving entire app designer GUI

45 visualizaciones (últimos 30 días)
Ali razi
Ali razi el 9 de Oct. de 2022
Comentada: Simon Chan el 10 de Oct. de 2022
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

Respuestas (1)

Simon Chan
Simon Chan el 9 de Oct. de 2022
It support figure object and hence you should use:
exportapp(app.UIFigure,[filepath filename]);
  4 comentarios
Ali razi
Ali razi el 9 de Oct. de 2022
exportgraphics with app.UIAxes or app.UIFigure only export the Axes and not in 500DPI (with the .'Resolution',500).
On the other hand exportapp(app.UIFigure,[filepath filename]); save the GUI but with 96DPI.
Any idea why and how to proceed?
Simon Chan
Simon Chan el 10 de Oct. de 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')

Iniciar sesión para comentar.

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by