问题
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