Dynamic Output File Naming - Screen Capture

조회 수: 1 (최근 30일)
Al Onen
Al Onen 2011년 7월 14일
Hello, I have a loop for some image processing and at the end of the each loop, I have to take a screenshot of Matlab. (for my case, imwrite or saveas functions are not applicable for me, that's why I have to use screen capture.)
For this, I've found the following Java-based code;
robo = java.awt.Robot;
t = java.awt.Toolkit.getDefaultToolkit();
rectangle = java.awt.Rectangle(t.getScreenSize());
image = robo.createScreenCapture(rectangle);
filehandle = java.io.File('screencapture.jpg');
javax.imageio.ImageIO.write(image,'jpg',filehandle);
imageview('screencapture.jpg');
I have a basic loop of i.e. 'for i=1:N' and I need to create output files with the "i" name of the loop i.e. for 1st loop, output name should be "1.jpg", second "2.jpg"... etc.
I will be very faithful if you can guide me on this. Thank you very much in advance.

채택된 답변

Daniel Shub
Daniel Shub 2011년 7월 14일
I think if you change
filehandle = java.io.File('screencapture.jpg');
to
filehandle = java.io.File([num2str(i), '.jpg']);
you should get what you want. The imageview('screencapture.jpg'); will not work anymore though, you will also need to change that ...
  댓글 수: 1
Al Onen
Al Onen 2011년 7월 14일
Thank you Daniel, that works perfect.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by