How to "Save As .jpg" a figure programmically?

2 次查看(过去 30 天)
I've got a following problem: I need to automatically save figures as jpg files. This is easily done by hand
(open the File-menu, go to Save As, choose jpg image). But how to do this programmically?
Mikael

采纳的回答

Jan
Jan 2019-3-20
编辑:Jan 2019-3-20
Either by
print(FigureHandle, 'C:\temp\File.jpg')
or
pause(0.02); % Magic update of java elements - don't ask me why...
F = getframe(FigureHandle);
[X, map] = frame2im(F);
imwrite(X, map, 'C:\temp\File.jpg');
  1 个评论
Mikael Agopov
Mikael Agopov 2019-3-26
编辑:Mikael Agopov 2019-3-26
Thanks to Walter and Jan,
Solved the issue using print():
1) take the screencapture and save it to the object as a property
sc=print('-RGBImage');
set(obj,'ScreenCapt',sc);
...
2) later, when saving results, open up a dummy figure (not visible), imshow the screencapture on it and print the figure
into a file.
H=figure('Visible','off');
imshow(get(obj,'ScreenCapt'));
print(H,'screencapt.png','-dpng');

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by