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

조회 수: 2 (최근 30일)
Mikael Agopov
Mikael Agopov 2019년 3월 20일
편집: Mikael Agopov 2019년 3월 26일
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