This has probably been done a million times before so if someone can point me to an example I would appreciate it. I want to copy a small part of the screen to analyse so I thought it would be good to see the copied block in a picture on my form but the method I have used gives rubbish. It doesn't match any part of the screen let alone the bit I want although some of the colours seem to match it just looks scrambled up. The size of the picture matches the block I mark on the screen with top left and bottom right mouse positions but the content doesn't.
Here is the code that does the copying and placing in a picture that I cobbled together by looking at the Wiki and I could understand or maybe not.
masbmp := TBitmap.Create;
masbmp.Height := ymbot-ymtop;
masbmp.Width := xmmax;
mastp.Y:=tp.Y;
mastp.X:=tp.X;
for py:=ymtop to ymbot do
begin
for px:=0 to xmmax-1 do
begin
masbmp.Canvas.Pixels[px,py]:=ScrBitmap.Canvas.Pixels[mastp.X,mastp.Y];
mastp.X:=mastp.X+1;
end;
mastp.Y:=mastp.Y+1;
end;
with Image1.Picture.Bitmap do begin
SetSize(xmmax,ymmax);
end;
Image1.Canvas.Draw(0,0,masbmp);