Screenshotting!

Just starting out? Need help? Post your questions and find answers here.
DBAlex
User
User
Posts: 12
Joined: Tue Jul 05, 2005 3:57 pm

Screenshotting!

Post by DBAlex »

Hi, I have this code in my main loop...

Code: Select all

    
If KeyboardPushed(#PB_Key_p)
SaveSprite(6, "c:/screenshot.bmp")
GrabSprite(6,0,0,640,480)
EndIf
For taking a screenshot, But the image saves wierdly... Heres the bmp converted to JPG of what It looks like...

Image

So how can I correct this?

Im using the OpenScreen for graphics...

Thanks if you can help :? !
coma
Enthusiast
Enthusiast
Posts: 164
Joined: Fri Aug 15, 2003 3:46 am
Location: Canada

Post by coma »

hi.
try to grab before saving.
DBAlex
User
User
Posts: 12
Joined: Tue Jul 05, 2005 3:57 pm

Post by DBAlex »

Ive tried that too...

Still mumbled...

Forgot to change the lines round after that :oops:
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

Try this ( code from ?? )


Code: Select all

;capture a piece of screen 
Procedure.l CaptureScreen(Left.l, Top.l, Width.l, Height.l) 
  dm.DEVMODE 
  BMPHandle.l 
  srcDC = CreateDC_("DISPLAY", "", "", dm) 
  trgDC = CreateCompatibleDC_(srcDC) 
  BMPHandle = CreateCompatibleBitmap_(srcDC, Width, Height) 
  SelectObject_( trgDC, BMPHandle) 
  BitBlt_( trgDC, 0, 0, Width, Height, srcDC, Left, Top, #SRCCOPY) 
  DeleteDC_( trgDC) 
  ReleaseDC_( BMPHandle, srcDC) 
  ProcedureReturn BMPHandle 
EndProcedure 

ScreenCaptureAddress = CaptureScreen(0, 0, 1024, 768) 

UseJPEGImageEncoder() 


CreateImage(0, 1024, 768) 
StartDrawing(ImageOutput()) 
DrawImage(ScreenCaptureAddress, 0, 0) 
StopDrawing() 
SaveImage(0, "d:\Screenshot.jpg",#PB_ImagePlugin_JPEG)
DBAlex
User
User
Posts: 12
Joined: Tue Jul 05, 2005 3:57 pm

Post by DBAlex »

Thankyou for all the help!

I found a good screenshot program now though!

:)
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

My screenshot code :wink: :

Code: Select all

Enumeration ;Sprites
  #spr_ScreenShot
EndEnumeration
Global ScreenShots.w

Procedure SaveScreen()
  ScreenShots + 1
  GrabSprite(#spr_ScreenShot,0,0,640,480)
  SaveSprite(#spr_ScreenShot,"screenshot"+Str(ScreenShots)+".bmp")
  FreeSprite(#spr_ScreenShot)
EndProcedure
I like logic, hence I dislike humans but love computers.
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post by Nik »

Please set Screenshots.w as Static thats better style and its safer^^
bye Nik
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> GrabSprite(#spr_ScreenShot,0,0,640,480)

FYI: while this works, it requires that DirectX be installed, which not all PCs may have.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Post Reply