Hi Abhishek,
I faced a similar issue in MATLAB R2020a but I observed that it was working fine with MATLAB R2020b onwards. So, a possible fix could be to try upgrading MATLAB to a newer version. There is also a workaround which I found, instead of passing 'app.UIFigure', I tried passing a component inside it which in my case was the axes object 'app.UIAxes' and it was working fine with it.
% Button pushed function: Button
function ButtonPushed(app, event)
% Plot some data
plot(app.UIAxes, rand(1,10));
app.Label.Text = 'Data Plotted!';
end
% Button pushed function: SaveImageButton
function SaveImageButtonPushed(app, event)
figure(app.UIFigure);
exportgraphics(app.UIAxes,'screenshot.jpg') %Works Fine
end
Hope it helps!