December 04, 2020, 11:28:55 AM

Author Topic: [bmx] Screen Capture Mod by TomToad [ 1+ years ago ]  (Read 712 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] Screen Capture Mod by TomToad [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : Screen Capture Mod
Author : TomToad
Posted : 1+ years ago

Description : Put this code into (BlitzMAX)mod   oad.modcapture.mod directory and build the module.
Usage:
Function ScreenCapture:TPixMap()

Will capture the screen and return it in a pixmap.  If you call this function before calling Graphics, you'll capture the desktop image.

Function GetScreenCapturWidth:int()

will return the width of the captured image

Function GetScreenCaptureHeight:int()

Will get the Height of the captured image

Edit:  Don't need all the lines I commented out :)


Code :
Code: BlitzMax
  1. Module toad.capture
  2.  
  3. Import BRL.Pixmap
  4. Import pub.Win32
  5. Import BRL.Basic
  6.  
  7. Extern "Win32"
  8.         Function GetPixel:Int(hdc:Int,x:Int,y:Int)
  9. End Extern
  10.  
  11. Private
  12. Global Width:Int
  13. Global Height:Int
  14.  
  15. Public
  16. Function ScreenCapture:TPixmap()
  17.         Local Pixmap:TPixmap
  18.         Local Pixel:Int
  19.         Local hdc:Int = GetDC(Null)
  20.        
  21.         Width:Int = GetDeviceCaps(hdc,HORZRES)
  22.         Height:Int = getdevicecaps(hdc,VERTRES)
  23.         Pixmap = CreatePixmap(Width,Height,PF_RGBA8888)
  24.         For Local y = 0 To Height - 1
  25.                 For Local x = 0 To Width - 1
  26.                         Pixel = GetPixel(hdc,x,y)
  27.                         WritePixel(PixMap,x,y,$FF000000+(Pixel & $ff)Shl 16+(Pixel & $ff00)+(Pixel & $ff0000)Shr 16)
  28.                 Next
  29.         Next
  30.        
  31.         Return PixMap
  32.  
  33. End Function
  34.  
  35. Function GetScreenCaptureWidth:Int()
  36.         Return Width
  37. End Function
  38.  
  39. Function GetScreenCaptureHeight:Int()
  40.         Return Height
  41. End Function


Comments :


Boiled Sweets(Posted 1+ years ago)

 I use this to draw the desktop in the loop
Code: [Select]
DrawPixmap( desktopPixMap, 0, 0 )
This causes the screen saver to run rather jerkily, is there a better way?


TomToad(Posted 1+ years ago)

 Try loading the pixmap into a TImage
Code: [Select]
Local DeskTopImage:TImage = LoadImage(desktopPixMap)You can capture and load all in one line with
Code: [Select]
Local DesktopImage:TImage = LoadImage(ScreenCapture())That's the way I did it in my SpinIt screensaver.  One problem though is that some older cards can't handle a TImage as big as the desktop so you might be better off loading as an animation.
Code: [Select]
Local DeskTopImage:TImage = LoadAnimImage(ScreenCapture(),TileWidth,TileHeight,0,CellWidth*CellHeight)Where TileWidth and TileHeight are the width and height of the tiles in pixels, and CellWidth and CellHeight are the number of tiles in the X and Y directions.


Who was John Galt?(Posted 1+ years ago)

 Cheers Tom this one was useful for me.


fredborg(Posted 1+ years ago)

 Hi,GetPixel is terribly slow when Aero is enabled in Vista. It's much faster to copy the screen to a different bitmap and then read from that.This is one way of doing that:
Code: [Select]
Import pub.win32

SuperStrict

Extern "win32"
Function ReleaseDC:Int(hwnd:Int,hdc:Int)
Function GetPixel:Int(hdc:Int,x:Int,y:Int)
End Extern

Const SRCCOPY:Int = $CC0020

Function GrabScreen:TPixmap(x:Int=0,y:Int=0,width:Int=0,height:Int=0)

Local hdc:Int = GetDC(Null)

If width  <= 0 Then width  = 100000000000
If height <= 0 Then height = 100000000000

Local maxWidth:Int = GetDeviceCaps(hdc,HORZRES)-x
Local maxHeight:Int = GetDeviceCaps(hdc,VERTRES)-y

width = Min(maxWidth,width)
height = Min(maxHeight,height)

Local newHdc:Int = CreateCompatibleDC(hdc)
If newHdc = 0 Then Return Null

Local newBmp:Int = CreateCompatibleBitmap(hdc,width,height)
If newBmp = 0
ReleaseDC(Null,newHdc)
Return Null
EndIf

If SelectObject(newHdc, newBmp) = False
Return Null
EndIf

If BitBlt(newHdc,0,0,width,height,hdc,x,y,SRCCOPY) = False
Return Null
EndIf

Local pixmap:TPixmap = CreatePixmap(width,height,PF_RGBA8888)

For Local y:Int = 0 Until height
For Local x:Int = 0 Until width
Local pixel:Int = GetPixel(newHdc,x,y)
WritePixel(pixmap,x,y,$FF000000+(pixel & $ff) Shl 16 + (pixel & $ff00) + (pixel & $ff0000) Shr 16)
Next
Next

DeleteObject(newBmp)
ReleaseDC(Null,newHdc)

Return pixmap

End Function


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal