Capture screenshot on second monitor HDMI input source
Afficher commentaires plus anciens
Hi,
I have dual monitors connected to the desktop via DP connections. I also have video feed that I would like to take periodic screenshots of. I can connect my video feed to one monitor via HDMI input. When I attempt to take a screenshot of the video, the screenshot returns what is displayed on the DP connection, not the HDMI connection. Is there a way to capture screenshots of the HDMI input on the second monitor while operating MATLAB through the DP on the first monitor?
Below is my code for screencapture. This code works fine when taking screenshot of DP monitor input.
% Take a screenshot and focus on desired location
robot = java.awt.Robot();
pos = [200 150 500 400]; % [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
% Uncomment below to show image
imshow(imgData)
imwrite(imgData,'out.png')
% Read the image
I = imread("out.png");
2 commentaires
Are you using
get(0,'MonitorPositions')
to get the logical positions of the monitors, so that you can figure out the correct relative coordinates to capture? Such as
monpos = get(0,'MonitorPositions');
monpos = monpos(end,:); %last monitor
pos = [200 150 500 400]; % [left top width height]
rect = pos;
rect(1:2) = rect(1:2) + monpos(1:2); %might need to fudge it by +/- 1
cap = robot.createScreenCapture(rect);
Thomas
le 21 Juil 2025
Réponses (0)
Catégories
En savoir plus sur Video Formats and Interfaces dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!