how to save a screenshot (matlab)

依然范特西╮ 提交于 2019-12-13 18:31:30

问题


I am trying to save a screenshot in a specific directory using Matlab. I am able to generate the screenshot but I find no solution to save it in a specific directory. I have tried save and saveas but get error messages...Any ideas? Really appreciate any help.

robo = java.awt.Robot;
t = java.awt.Toolkit.getDefaultToolkit();
rectangle = java.awt.Rectangle(t.getScreenSize());
image = robo.createScreenCapture(rectangle);
filehandle = java.io.File(sprintf('%s_screencapture.jpg',current_stock));

javax.imageio.ImageIO.write(image,'jpg',filehandle);

dest_dir = 'D:\screenshot\';

回答1:


Does this work for you?

filepath = fullfile(dest_dir, sprintf('%s_screencapture.jpg',current_stock));

filehandle = java.io.File(filepath);

javax.imageio.ImageIO.write(image,'jpg',filehandle);

PS - best not to use image or rectangle as variable names, as they are the names of built-in MATLAB commands.



来源:https://stackoverflow.com/questions/18186400/how-to-save-a-screenshot-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!