我需要在应用程序之外截图:
X:centerOfScreen-100到centerOfScreen + 100
Y:centerOfScreen-100到centerOfScreen + 100
model.getSolver().plugMonitor(new IMonitorOpenNode() {
@Override
public void afterOpenNode() {
System.out.println(s.getDecisionPath().getLastDecision());
}
});
我知道现在写的很糟糕,只是为了测试。我查看了大部分代码,但我无法弄清楚为什么它只会复制屏幕的左上角区域。
GetDC(0)返回整个屏幕的DC ......对吗?我做错了什么?
答案 0 :(得分:1)
此代码捕获指定桌面的任何区域,将其放入TBitmap,并在表单上的TImage中显示该位图。
(我只是从位置100开始抓取400 x 400像素区域,100用于演示,但它也适用于其他区域。根据需要进行调整。)
</head>
<body>
<h1>NBA 2016</h1>
<p id="slogan"><i>Basketball never stops</i></p>
<div class="div">
<div id="table">
<h2 class="content">Atlantic</h2>
<ul><li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/bos.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/bos/boston-celtics">Boston Celtics</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/bkn.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/bkn/brooklyn-nets">Brooklyn Nets</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/ny.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/ny/new-york-knicks">New York Knicks</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/phi.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/phi/philadelphia-76ers">Philadelphia 76ers</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/tor.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/tor/toronto-raptors">Toronto Raptors</a></li></ul>
</div>
<div id="table">
<h2 class="content">Central</h2>
<ul><li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/chi.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/chi/chicago-bulls">Chicago Bulls</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/cle.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/cle/cleveland-cavaliers">Cleveland Cavaliers</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/det.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/det/detroit-pistons">Detroit Pistons</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/ind.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/ind/indiana-pacers">Indiana Pacers</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/mil.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/mil/milwaukee-bucks">Milwaukee Bucks</a></li></ul>
</div>
<div id="table">
<h2 class="content">Northwest</h2>
<ul><li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/den.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/den/denver-nuggets">Denver Nuggets</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/min.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/min/minnesota-timberwolves">Minnesota Timberwolves</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/okc.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/okc/oklahoma-city-thunder">Oklahoma City Thunder</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/por.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/por/portland-trail-blazers">Portland Trail Blazers</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/utah.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/utah/utah-jazz">Utah Jazz</a></li></ul>
</div>
<div id="table">
<h2 class="content">Pacific</h2>
<ul><li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/gsw.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/gsw/golden-state-warriors">Golden State Warriors</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/lac.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/lac/los-angeles-clippers">LA Clippers</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/lal.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/lal/los-angeles-lakers">Los Angeles Lakers</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/pho.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/pho/phoenix-suns">Phoenix Suns</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/sac.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/sac/sacramento-kings">Sacramento Kings</a></li></ul>
</div>
<div id="table">
<h2 class="content">Southeast</h2>
<ul><li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/atl.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/atl/atlanta-hawks">Atlanta Hawks</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/cha.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/cha/charlotte-hornets">Charlotte Hornets</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/mia.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/mia/miami-heat">Miami Heat</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/orl.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/orl/orlando-magic">Orlando Magic</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/was.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/was/washington-wizards">Washington Wizards</a></li></ul>
</div>
<div id="table">
<h2 class="content">Southwest</h2>
<ul><li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/dal.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/dal/dallas-mavericks">Dallas Mavericks</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/hou.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/hou/houston-rockets">Houston Rockets</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/mem.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/mem/memphis-grizzlies">Memphis Grizzlies</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/no.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/no/new-orleans-pelicans">New Orleans Pelicans</a></li>
<li><img style="vertical-align:middle" src="http://a.espncdn.com/combiner/i?img=/i/teamlogos/nba/500/sas.png&h=25&w=25"><a href="http://www.espn.com/nba/team/_/name/sas/san-antonio-spurs">San Antonio Spurs</a></li></ul>
</div>
</div>
</body>
</html>
为了证明它在任何屏幕区域都能正常运行,此代码还会捕获我的辅助监视器的右下角并进行此更改:
procedure TForm1.Button1Click(Sender: TObject);
var
DeskDC: HDC;
SrcRect, DestRect: TRect;
DeskCanvas: TCanvas;
Bmp: TBitmap;
begin
DeskDC := GetDC(GetDesktopWindow);
try
DeskCanvas := TCanvas.Create;
DeskCanvas.Handle := DeskDC;
SrcRect := Rect(100,
100,
500,
500);
DestRect := Rect(0,
0,
SrcRect.Right - SrcRect.Left,
SrcRect.Bottom - SrcRect.Top);
Bmp := TBitmap.Create;
try
Bmp.SetSize(DestRect.Width, DestRect.Height);
Bmp.Canvas.CopyRect(DestRect, DeskCanvas, SrcRect);
Image1.Picture.Assign(Bmp);
finally
Bmp.Free;
end;
finally
ReleaseDC(GetDesktopWindow, DeskDC);
end;
end;
答案 1 :(得分:0)
我正在使用此代码复制整个桌面:
DeskTop := TCanvas.Create;
Bmp := TBitmap.Create;
Bmp.Width := Screen.DesktopWidth;
Bmp.Height := Screen.DesktopHeight;
try
with DeskTop do
Handle := GetWindowDC(GetDesktopWindow);
with Bmp.Canvas do
CopyRect(Rect(0, 0,Bmp.Width , Bmp.Height),DeskTop, Screen.DesktopRect);
.....
finally
Bmp.Free;
DeskTop.Free;
end