|
source_x - x coordinate of the top-left corner of the area to copy source_y - y coordinate of the top-left corner of the area to copy width - width of the area, in pixels height - height of the area, in pixels dest_x - x coordinate to copy the area to dest_y - y coordinate to copy the area to src_buffer (optional) - buffer to copy from; the current buffer (default) dest_buffer (optional) - buffer to copy to; the current buffer (default) |
|
Copies a rectangle of pixels from one buffer to another, or within one buffer. Give it the top-left corner and size of the area, and where to put it. Either buffer can be the screen buffers or an ImageBuffer()/TextureBuffer(), so this is the tool for grabbing a finished piece of screen into an image, stamping an image area onto another, or duplicating part of the screen - a photograph mini-game, a rear-view mirror, a static background captured once and blitted back each frame. Note the second pair of numbers is the SIZE of the area, not its bottom-right corner - a classic slip. To capture what you have just drawn in a frame, copy from BackBuffer() before you Flip. For grabbing into an image, GrabImage does a similar job and hands you an image handle directly. See also: GrabImage, ImageBuffer, BackBuffer, CopyPixel, SetBuffer. |
; CopyRect Example
; ----------------
Graphics 640,480,0,2
SetBuffer BackBuffer()
SeedRnd MilliSecs()
; Bouncing bubbles give the monitor panel something to watch
Dim bx#(9),by#(9),bvx#(9),bvy#(9)
For i=0 To 9
bx(i)=Rnd(40,560)
by(i)=Rnd(80,400)
bvx(i)=Rnd(1,3)
bvy(i)=Rnd(1,3)
Next
While Not KeyDown(1)
Cls
; Move and draw the bubbles
For i=0 To 9
bx(i)=bx(i)+bvx(i)
by(i)=by(i)+bvy(i)
If bx(i)<0 Or bx(i)>600 Then bvx(i)=-bvx(i)
If by(i)<40 Or by(i)>440 Then bvy(i)=-bvy(i)
Color 50+i*20,150,255-i*20
Oval bx(i),by(i),40,40,1
Next
; A 160x120 source window follows the mouse (kept on screen)
sx=MouseX()-80
sy=MouseY()-60
If sx<0 Then sx=0
If sx>480 Then sx=480
If sy<0 Then sy=0
If sy>360 Then sy=360
; CopyRect duplicates that region into the top-right monitor panel
CopyRect sx,sy,160,120,470,30,BackBuffer(),BackBuffer()
; Frame the source window and the monitor panel
Color 255,255,0
Rect sx,sy,160,120,0
Color 255,255,255
Rect 469,29,162,122,0
Text 0,0,"Move the mouse - CopyRect mirrors the yellow window top-right Esc: exit"
Text 0,20,"CopyRect "+sx+","+sy+",160,120,470,30,BackBuffer(),BackBuffer()"
Flip
Wend
End