Here are two examples. Both work well on my PC.
Code: Select all
Global.i SearchPatternSize, *SearchPattern
Global *FirstImage, *LastPartialImage, LastPartialImageHeight
Procedure MakeDesktopScreenshot(ImageNr, ImageX, ImageY, ImageWidth, ImageHeight, SnapshotNr)
Protected hImage, hDC, hWnd, DeskDC, Addr
Protected Pitch, iFormat, iBytes, LastY, Y
Protected *Buffer
Protected ScanLinesToCompare
hImage = CreateImage(ImageNr, ImageWidth, ImageHeight)
If hImage
hDC = StartDrawing(ImageOutput(ImageNr))
If hDC
hWnd=GetDesktopWindow_()
DeskDC = GetDC_(hWnd)
BitBlt_(hDC, 0, 0, ImageWidth, ImageHeight, DeskDC, ImageX, ImageY, #SRCCOPY)
*Buffer = DrawingBuffer()
Pitch = DrawingBufferPitch()
iFormat = DrawingBufferPixelFormat()
LastY = ImageHeight - 1
If (iFormat & (#PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY)) = (#PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY)
;ScanLinesToCompare = 10
;ScanLinesToCompare = 3
ScanLinesToCompare = 1
If SnapshotNr = 1
SearchPatternSize = ScanLinesToCompare * Pitch
*SearchPattern = AllocateMemory(SearchPatternSize)
If *SearchPattern
CopyMemory(*Buffer, *SearchPattern, SearchPatternSize)
Else
hImage = 0
EndIf
*FirstImage = AllocateMemory(Pitch * ImageHeight)
If *FirstImage
CopyMemory(*Buffer, *FirstImage, Pitch * ImageHeight)
Else
hImage = 0
EndIf
Else
LastY - ScanLinesToCompare
For Y = LastY To 0 Step -1
If CompareMemory(*Buffer + Pitch * Y, *SearchPattern, SearchPatternSize)
If y * Pitch > 0
*LastPartialImage = AllocateMemory(y * Pitch)
If *LastPartialImage
CopyMemory(*Buffer, *LastPartialImage, y * Pitch)
LastPartialImageHeight = y
Debug "Image height to be added at the end of the first image: " + LastPartialImageHeight
EndIf
EndIf
Break
EndIf
Next
EndIf
EndIf
StopDrawing()
ReleaseDC_(hWnd, DeskDC)
; image for verification
CompilerIf #PB_Compiler_Debugger
Protected Image
If *LastPartialImage
Image = CreateImage(#PB_Any, ImageWidth, y + ImageHeight)
If Image
Debug "Image #" + Str(Image) + " = #2 "
If StartDrawing(ImageOutput(Image))
*Buffer = DrawingBuffer()
If (DrawingBufferPixelFormat() & (#PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY)) = (#PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY)
CopyMemory(*LastPartialImage, *Buffer, y * Pitch)
If *FirstImage
CopyMemory(*FirstImage, *Buffer + y * Pitch, MemorySize(*FirstImage))
EndIf
EndIf
StopDrawing()
EndIf
EndIf
EndIf
CompilerEndIf
Else
FreeImage(ImageNr)
hImage = 0
EndIf
EndIf
ProcedureReturn hImage
EndProcedure
Procedure CreateFinalizeSnapshot(ImageNr, Width, Height) ;, SnapshotNr)
Protected hImage
If *LastPartialImage And *FirstImage
hImage = CreateImage(ImageNr, Width, Height + LastPartialImageHeight)
If hImage
If StartDrawing(ImageOutput(ImageNr))
*BufferTemp = DrawingBuffer()
LastPartialImageSize = MemorySize(*LastPartialImage)
If (DrawingBufferPixelFormat() & (#PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY)) = (#PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY)
CopyMemory(*LastPartialImage, *BufferTemp, LastPartialImageSize)
CopyMemory(*FirstImage, *BufferTemp + LastPartialImageSize, MemorySize(*FirstImage))
EndIf
StopDrawing()
EndIf
EndIf
EndIf
If *FirstImage : FreeMemory(*FirstImage) : *FirstImage = 0 : EndIf
If *LastPartialImage : FreeMemory(*LastPartialImage) : *LastPartialImage = 0 : EndIf
ProcedureReturn hImage
EndProcedure
#const_x = 3
#const_y = 122
#const_w = 1656
#const_h = 675
Sleep_(2000)
If MakeDesktopScreenshot(0, #const_x, #const_y, #const_w, #const_h, 1)
Beep_(2000, 400)
Sleep_(5000) ;time to scroll screen
If MakeDesktopScreenshot(1, #const_x, #const_y, #const_w, #const_h, 2)
; to do
If CreateFinalizeSnapshot(2, #const_w, #const_h) ;;, 2)
ShowLibraryViewer("image")
CallDebugger
EndIf
EndIf
EndIf
If *SearchPattern
FreeMemory(*SearchPattern)
EndIf
Code: Select all
Global.i SearchPatternSize, *SearchPattern
Global LastPartialImage
Procedure MakeDesktopScreenshot(ImageNr, ImageX, ImageY, ImageWidth, ImageHeight, SnapshotNr)
Protected hImage, hDC, hWnd, DeskDC, Addr
Protected Pitch, iFormat, iBytes, LastY, Y
Protected *Buffer
Protected ScanLinesToCompare, LastPartialImageHeight
hImage = CreateImage(ImageNr, ImageWidth, ImageHeight)
If hImage
hDC = StartDrawing(ImageOutput(ImageNr))
If hDC
hWnd=GetDesktopWindow_()
DeskDC = GetDC_(hWnd)
BitBlt_(hDC, 0, 0, ImageWidth, ImageHeight, DeskDC, ImageX, ImageY, #SRCCOPY)
*Buffer = DrawingBuffer()
Pitch = DrawingBufferPitch()
iFormat = DrawingBufferPixelFormat()
LastY = ImageHeight - 1
If (iFormat & (#PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY)) = (#PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY)
;ScanLinesToCompare = 3
;ScanLinesToCompare = 10
ScanLinesToCompare = 1
If SnapshotNr = 1
SearchPatternSize = ScanLinesToCompare * Pitch
*SearchPattern = AllocateMemory(SearchPatternSize)
If *SearchPattern
CopyMemory(*Buffer, *SearchPattern, SearchPatternSize)
Else
hImage = 0
EndIf
Else
LastY - ScanLinesToCompare
For Y = LastY To 0 Step -1
If CompareMemory(*Buffer + Pitch * Y, *SearchPattern, SearchPatternSize)
LastPartialImageHeight = 0
If Y * Pitch > 0
LastPartialImageHeight = y
Debug "Image height to be added at the end of the first image: " + LastPartialImageHeight
EndIf
Break
EndIf
Next
EndIf
EndIf
StopDrawing()
ReleaseDC_(hWnd, DeskDC)
If LastPartialImageHeight > 0 And ImageHeight - LastPartialImageHeight > 0
LastPartialImage = GrabImage(ImageNr, #PB_Any, 0, ImageHeight - LastPartialImageHeight, ImageWidth, LastPartialImageHeight)
EndIf
Else
FreeImage(ImageNr)
hImage = 0
EndIf
EndIf
ProcedureReturn hImage
EndProcedure
Procedure CreateFinalizeSnapshot(ImageNr, Width, Height) ;, SnapshotNr)
Protected hImage, ImgH
If LastPartialImage And IsImage(LastPartialImage)
ImgH = ImageHeight(LastPartialImage)
EndIf
hImage = CreateImage(ImageNr, Width, Height + ImgH)
If hImage
If StartDrawing(ImageOutput(ImageNr))
DrawImage(ImageID(0), 0, 0)
If ImgH
DrawImage(ImageID(LastPartialImage), 0, ImageHeight(0))
;DrawImage(ImageID(LastPartialImage), 0, Height)
EndIf
StopDrawing()
EndIf
EndIf
ProcedureReturn hImage
EndProcedure
#const_x = 3
#const_y = 122
#const_w = 1656
#const_h = 675
Sleep_(2000)
If MakeDesktopScreenshot(0, #const_x, #const_y, #const_w, #const_h, 1)
Beep_(2000, 400)
Sleep_(5000) ;time to scroll screen
If MakeDesktopScreenshot(1, #const_x, #const_y, #const_w, #const_h, 2)
; to do
If CreateFinalizeSnapshot(2, #const_w, #const_h) ;;, 2)
;SaveImage(0, "z:\test.bmp")
ShowLibraryViewer("image")
CallDebugger
EndIf
EndIf
EndIf
If *SearchPattern
FreeMemory(*SearchPattern)
EndIf
Edit:
By the way, I have to point out an issue. Make sure you use the brackets well.
Code: Select all
PixelFormat = #PB_PixelFormat_24Bits_BGR ; For example, if the return value of DrawingBufferPixelFormat() is like this.
Debug Bool(PixelFormat & #PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY) ; 1
Debug Bool(PixelFormat & (#PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY)) ; 1
Debug Bool((PixelFormat & #PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY) = (#PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY)) ; 1
Debug ""
; To compare whether the value of variable #1 contains both values of variable #2 and #3, it should be as follows.
Debug Bool(PixelFormat & (#PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY) = (#PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY)) ; 0 correct result
Debug "-----------------------"
PixelFormat = #PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY ; For example, if the return value of DrawingBufferPixelFormat() is like this.
Debug Bool(PixelFormat & #PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY) ; 1
Debug Bool(PixelFormat & ( #PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY)) ; 1
Debug Bool((PixelFormat & #PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY) = (#PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY)) ; 1
Debug ""
Debug Bool(PixelFormat & (#PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY) = (#PB_PixelFormat_24Bits_BGR | #PB_PixelFormat_ReversedY)) ; 1 correct result