Capture screenshot on second monitor HDMI input source
이전 댓글 표시
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
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
2025년 7월 21일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Video Formats and Interfaces에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!