Save an image snapshot of a GUI

조회 수: 6 (최근 30일)
John
John 2012년 5월 3일
편집: Walter Roberson 2024년 10월 22일
Hi, I have created a GUI which enables a user to load an image. This image is then displayed in an axes. The user then highlights a region of interest within the image using the roipoly tool.
However, I would like to include a button which enables the user to take a 'snapshot' of the GUI which is then saved to a folder. I have tried using the following functions;
print('-djpeg','-r1200',filePath)
and
saveas(handles.figure1,filePath,'jpg');
both of which result in quite low quality images. More importantly, the location of most of the UI controls are changed resulting in an output which does not mirror the GUI's state.
I have tried using the, set(gcf,'PaperPositionMode','auto'); and set(gcf,'InvertHardcopy','off'); options however these resulted in an error.
Any ideas?
kind regards, John
  댓글 수: 1
Adam Danz
Adam Danz 2020년 10월 20일
In anyone is looking for a solution to taking snapshots with uifigures and apps, exportapp() was released in r2020b (see community highlight).

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

답변 (2개)

Image Analyst
Image Analyst 2012년 5월 3일
And don't use JPEG - it gives crappy images. Use PNG instead.

Juan Conde
Juan Conde 2024년 10월 22일
편집: Walter Roberson 2024년 10월 22일
Although exportapp() is a good option, it does not work in older GUIs created with the figure function.
A workaround is given in:
where it shows how to use getframe and imwrite to this purpose:
plot(1:10)
F = getframe(gcf);
imwrite(F.cdata,"myplot.bmp")

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by