MATLAB Answers

How can I capture a screenshot WITH the cursor displayed in Matlab?

21 views (last 30 days)
Thomas Körner
Thomas Körner on 4 May 2020
Commented: Thomas Körner on 6 May 2020
Hi,
I want to make a screenshot of my current desktop and want the cursor be displayed in the picture. All methods I tried so far didnt display the cursor (cursor is just invisible). Any method to do it?
EDIT: For those who want to know how I solved my problem: I didn't find any direct method to do it inside Matlab. Instead I use OBS to capture a region of my screen. In my case its a computer game that is in window mode and takes only a third of my actual screen. In the preview window of OBS I can then see a live footage of that game with a visible cursor. Then I do a screenshot of my screen in Matlab using the java robot class:
% Take screen capture
robot = java.awt.Robot();
pos = [0 0 3440 1440]; % [left top width height]
rect = java.awt.Rectangle(pos(1),pos(2),pos(3),pos(4));
cap = robot.createScreenCapture(rect);
% Convert to an RGB image
rgb = typecast(cap.getRGB(0,0,cap.getWidth,cap.getHeight,[],0,cap.getWidth),'uint8');
imgData = zeros(cap.getHeight,cap.getWidth,3,'uint8');
imgData(:,:,1) = reshape(rgb(3:4:end),cap.getWidth,[])';
imgData(:,:,2) = reshape(rgb(2:4:end),cap.getWidth,[])';
imgData(:,:,3) = reshape(rgb(1:4:end),cap.getWidth,[])';
% Show or save to file
imshow(imgData)
The next step would be to extract the area where the preview window of OBS is located (or: directly define the image capture position in pos = [...]).
The result is a picture of the game that contains a visible cursor and is loaded in the matlab workspace.
Of course if you want the cursor to be as big on the picture as in the game you will need to scale the preview window of OBS to the same size as the window of the game.

  0 Comments

Sign in to comment.

Answers (2)

Jason Nicholson
Jason Nicholson on 5 May 2020
Record the screen using Screen Recording in PowerPoint? A screen capture won't work but a screen recording will.

Hannes Ernst
Hannes Ernst on 5 May 2020
You could use a desktop Magnifier (e. g. the standard one from Microsoft called with the shortcut "Windows Key" + "+"). Just set it to 100 % (original scale) and make a screenshot from the desktop magnifier view. In case of pointing out code you could just mark the relevant passage.

  1 Comment

Thomas Körner
Thomas Körner on 5 May 2020
I oponed the tool and did a screenshot with matlab, but I still cant see the Cursor on the image.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!