Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / SaveImage trouble

Author
Message
niansenx
8
Years of Service
User Offline
Joined: 29th Jan 2016
Location:
Posted: 27th Feb 2016 17:11
Hello

I am trying to use SaveImage to save a screen print my code is this

initlevel()
loadlevel(levelno, "no")
sync()
getimage(1,0,0,2560,1440)
saveimage(1,"test.png")

The first two lines call functions that put sprites on the screen, and I can see them when I run the code. But the next two lines do not output anything. What am I doing wrong?

Many thanks
James
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 27th Feb 2016 19:30
If you're using the steam version, use the steam shortcut F11 (or F12) to take a screenshot.

But to answer your question, are you actually seeing anything onscreen before taking a screenshot?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th Feb 2016 21:45
Is this your first Sync()?
You need 2 Syncs to populate the backbuffer.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 28th Feb 2016 21:59
Sync clears the back buffer as its final act, ready for the next frame (if it did it first then it would clear any drawing you had done manually with DrawSprite, DrawObject, etc). As such you need to capture the image after rendering but before clearing, to do this use the Update/Render/Swap sequence instead of Sync like so

niansenx
8
Years of Service
User Offline
Joined: 29th Jan 2016
Location:
Posted: 29th Feb 2016 20:51
Hmm, I've taken an example of the help website, but the sameimage line doesn't seem to do anything. Am I right in thinking a png file should be saved in the project folder?

Setvirtualresolution(640,480)
ResetTimer()
//Create a Green Cross Image
swap()
Drawline(0,0,15,15,0,255,0)
Update(0)
Render()
Drawline(0,15,15,0,0,255,0)
Update(0)
Render()
GetImage(1,0,0,15,15)
//Save Image File
SaveImage(1,"temp.png")
SetClearColor(50,50,100)
//Create Sprite
id=LoadSprite("temp.png")
Do
If Timer()>15 Then Exit
Sync()
Loop
End
xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 29th Feb 2016 21:05
By default, the saved images actually appear in your C:\Users\YourName\AppData\Local\AGKApps\AppName\media folder. I just tried the code and it works as expected. You can modify the save directory via SetRawWritePath().
niansenx
8
Years of Service
User Offline
Joined: 29th Jan 2016
Location:
Posted: 29th Feb 2016 21:37
Finally worked it out. A combination of AppGameKit saving the images to a hidden folder ...AppData\Local\AGKApps\agk\media and getting the right mix of screen drawing commands. That will save me having to manually screen print one hundred images!

initlevel()
swap()
loadlevel(levelno, "no")
render()
getimage(10000+levelno,0,0,2560,1440)
saveimage(10000+levelno,"level_0" + str(levelno) + ".png")
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 1st Mar 2016 10:05
You might find this tutorial useful, or just drop the code module straight in. It is configurable to take screen shots in different ways.

The Ultimate Selfie
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt

Login to post a reply

Server time is: 2024-09-29 11:20:52
Your offset time is: 2024-09-29 11:20:52