Exportapp error in saving entire app designer GUI

조회 수: 44 (최근 30일)
Ali razi
Ali razi 2022년 10월 9일
댓글: Simon Chan 2022년 10월 10일
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

답변 (1개)

Simon Chan
Simon Chan 2022년 10월 9일
It support figure object and hence you should use:
exportapp(app.UIFigure,[filepath filename]);
  댓글 수: 4
Ali razi
Ali razi 2022년 10월 9일
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 2022년 10월 10일
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')

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by