Screen capture

BlitzPlus Forums/BlitzPlus Programming/Screen capture

julianbury(Posted 2009) [#1]
I need to take a screen shot and save it ...

snapscreen = LoadImage(Desktop())
SaveImage (snapscreen, CurrentDir$+"screenshot.bmp")
FreeImage(snapscreen)
End

But I get an error: "invalid image handle"

Can anybody please correct me?

Thank you for your kind attention and any suggestions :-)


schilcote(Posted 2009) [#2]
Desktopbuffer(), not desktop().

Looking at your code some more, I think you should just savebuffer(desktopbuffer()). I'm not sure your code will work.


julianbury(Posted 2009) [#3]
Hi schilcote,

Thanks for the hint!

This works ...
w = GadgetWidth(Desktop())
h = GadgetHeight(Desktop())
img = CreateImage(w, h)
CopyRect 0, 0, w, h, 0, 0, DesktopBuffer(), ImageBuffer(img)
SaveImage img, "C:\Downloads\screenshot.bmp"
Notify "Done"
End

Bye!

(-_-)


Ginger Tea(Posted 2009) [#4]
although any further screen grabs will overwrite the first
a search on the code archives and b3D forums will find this topic a gazzilion times, how different b+ is to b3D i dont know but most of the extra niceties in the other codes should migrate with little to no fuss
the most essential is the file name incrementation
hell even the screen grab key (normally F12 over its next door neighbour print screen) can be mapped to a joypad button


CloseToPerfect(Posted 2009) [#5]
make a variable like, imageNumber, and increase it every time you save a image and add the number to the end of you filename.
Something like

Global imageNumber = 0
Function screen_grab()
w = GadgetWidth(Desktop())
h = GadgetHeight(Desktop())
img = CreateImage(w, h)
CopyRect 0, 0, w, h, 0, 0, DesktopBuffer(), ImageBuffer(img)
fileName = "C:\Downloads\screenshot"+imageNumber+".bmp"
SaveImage img, fileName
imageNumber = imageNumber + 1
Notify "Done"
End Function 


untested but should work or give you the ideal of what to do.
CTP


SpaceTime(Posted 2009) [#6]
How do you get SaveImage to work? I have blitzmax with the gui and SaveImage is not a function I can use. Is it an add on or something which needs to be downloaded to work ? The reason why I'm asking is because I'd like to save an image in blitzmax.

By the way, if it is a function that needs to be downloaded, can you refer me to it

Thank you


Sauer(Posted 2009) [#7]
Ask this question in the BlitzMax beginners area, you'll get better replies there. Most BMax users don't even bother with this forum, and us sole B+ users are clueless about BlitzMax.


SpaceTime(Posted 2009) [#8]
Oh okay, I forgot, this is the Blitz Plus forum not the Blitzmax forum. So that explains why it might not work. Anyway, I just did some research and it looks like in Blitzmax SavePixmapPNG is the equivalent command to SaveImage in Blitz Plus.