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.

Newcomers DBPro Corner / Screenshot code not working, please help

Author
Message
Guardian
21
Years of Service
User Offline
Joined: 30th Sep 2003
Location:
Posted: 2nd Apr 2008 16:33
Hi, I wrote this code to take screenshots in my program. However for some reason will not take in sprites. It will show the 3d and 2d using basic 2d commands, but it will not save the sprites. thx for the help in advance.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 2nd Apr 2008 18:17
1. Have you SYNCed before taking the screenshot? If you don't use SYNC ON, you can easily take shots between full syncs and lose objects.

2. Are you GETting the correct bitmap? If you have loaded bitmaps and not SET CURRENT BITMAP back to 0, you are not taking an image of the screen.
KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 2nd Apr 2008 18:36
Was I just dreaming or wasn't there a function built in to DBPro that let you just press Print-Screen and it would save off a screenshot?

MSon
20
Years of Service
User Offline
Joined: 13th Jul 2004
Location: Earth, (I Think).
Posted: 2nd Apr 2008 18:42 Edited at: 2nd Apr 2008 18:54
i dont think so, but you could use this

Get a SnapShot of the Whole Screen


Or if you only want a Snapshot of a Small Area


Everyone Be Cool, You, Be Cool.
Guardian
21
Years of Service
User Offline
Joined: 30th Sep 2003
Location:
Posted: 2nd Apr 2008 20:10 Edited at: 2nd Apr 2008 20:12
thx guys, didn't work though:-(

Basically my code works like this. I have a single for loop that
draws a hexgrid. The hexgrid is made up of sprites. the background I have a textured plane with a world map on it. at the very end of the program after the syncs I have



So I do see the image the way I want it to come out. However the saved image is just the background plane. Also I'm working on bitmap 0. Its a very simple program, so there no back and forth with bitmaps going on, ironcially it was in hopes of avoiding this problem. Any other ideas, attached is the image of what it looks like when I try saving, and what it should look like when I use print screen.

Attachments

Login to view attachments
KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 2nd Apr 2008 20:34
That code (when needed) is immediately after the sync in your main loop?

Such as,



Guardian
21
Years of Service
User Offline
Joined: 30th Sep 2003
Location:
Posted: 2nd Apr 2008 21:03
Yup, but since I'm not using do loop, or syncing ever iteration of the for loop. It looks more like this





Since its double buffered nothing with update on screen by using a single sync at the end.
KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 2nd Apr 2008 21:23
Quote: "Since its double buffered nothing with update on screen by using a single sync "


Huh?

HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 2nd Apr 2008 21:34 Edited at: 2nd Apr 2008 21:50
try this :-



edit
to get the sprites back add show all sprites before the endif.

Dark Physics makes any hot drink go cold.
Guardian
21
Years of Service
User Offline
Joined: 30th Sep 2003
Location:
Posted: 2nd Apr 2008 21:52
Kistech, if you were to put a single sync outside of a loop, you would never see anything on screen. The reason is cause darkbasic uses a method called double buffering. Basically it tell holds the visual data in a buffer, when called again it release that data and stores the next set. You see what is released. In a loop you would never notice this, since sync is run twice. The sync just releases the buffer.

In order for something to show up on a non looped program you need to run sync twice. This allows the buffer to release and hold the next visual information.

HowDo, you have given me an idea. I should test to see if I were to copy it to a bitmap if the sprites themselves would also copy over. This might be a bug in DB, but I did a search and didn't see anything. Anyone else have any ideas why sprites might not be saving. thx guys.
KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 3rd Apr 2008 00:14 Edited at: 3rd Apr 2008 00:14
Quote: "if you were to put a single sync outside of a loop, you would never see anything on screen"


Right, knew that.

Quote: "In order for something to show up on a non looped program you need to run sync twice. "


Hmm. That might explain why some of my menus took some fancy coding to get them to show up properly. I'll have to give sync:sync a try in those situations and see what happens.

[edit]
Sure would be nice if something like that was documented...
[/edit]

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 3rd Apr 2008 02:03
Quote: "I should test to see if I were to copy it to a bitmap if the sprites themselves would also copy over. This might be a bug in DB, but I did a search and didn't see anything. Anyone else have any ideas why sprites might not be saving"


Sprites don't actually exist on the screen, so I'm pretty sure copying the bitmap won't have any effect.

If the finished screen of sprites are used as a background and don't change, try using Set Sprite to turn of the automatic background restore and use Paste Sprite (if necessary).

This should then work when you use Save Bitmap 0.

TDK_Man

Guardian
21
Years of Service
User Offline
Joined: 30th Sep 2003
Location:
Posted: 3rd Apr 2008 16:35
hi TDK,
I have tried what you suggested, however it still doesn't seem to work. I have tried both set sprite to turn off automatic background, as well as adding paste sprite. Niether together, nor seperate did they work :-( . I'm kinda running out of ideas. A question about the save image command . I don't understand what you mean by sprites don't actually exist, I always throught everything that was drawn to the screen was a bitmap, and save image would save everything on that screen, within that radius given . I appreciate all the help everyone is giving. Hopefully we can get this to work.
Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 3rd Apr 2008 20:03 Edited at: 3rd Apr 2008 23:10
Just to a look at Mson code and modded abit, also added another function called 'PasteAllSprites'. The result... it works, just need to remember to add a 1 on the end of get image or your images will come out square(get image num, left, top, right, down, 1).

Anyway heres a working demo, the screenshots will go to shared documents, but you can change that, also the saved image format is bmp, I know it's big but has the best quality. Png is tiny and has great quality for it's size, just not sure if I want my screenshots as a png. I don't know whats wrong with jpg, messes up the image some times, mainly text, also... if I don't stop now, i'll never.

Heres the demo:


Note: the function should really be called 'PasteAllVisibleSprites'

EDIT: if you just tested this your notice the path is missing '\', thats the forums fault.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 3rd Apr 2008 22:46 Edited at: 3rd Apr 2008 23:42
My apologies - I forgot that Save Bitmap was now obsolete in DBPro - I've been using DB Classic far too long!

Anyway, I should have said Save Image.

Does the following snippet not work for you?



TDK_Man

Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 3rd Apr 2008 23:04 Edited at: 3rd Apr 2008 23:07
TDK, you need to put a 1 on the end of get image or the image will come out sqaure and will only use the width of the image for the width and height. Not only that, it will round it up in multiples of 2(I think i said that right), so your 800 will become 1024 and something like 200 will become 256. My snippet works fine for this and also WindowsKiller's, but I'm not to sure what GDI is.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 3rd Apr 2008 23:39 Edited at: 3rd Apr 2008 23:51
Quote: "you need to put a 1 on the end of get image or the image will come out sqaure and will only use the width of the image for the width and height"


So it does - thanks for that. (My inexperience with DBPro I'm afraid)...

I was only concerned about the saved image actually containing the sprites and didn't spot that!

I'll edit my code snippet as you suggest.

[Edit] Oops - I missed your code snippet - sorry. Mine basically does the same and it was a waste of time posting it really!

TDK_Man

Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 4th Apr 2008 00:10 Edited at: 4th Apr 2008 00:10
But if you didn't post it, you wouldn't have learned to add a 1 on the end of get image when using DBP and I wouldn't have learned theres a command like 'CLS'. Thats the first time I've ever seen it, will come in handy, thanks
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 4th Apr 2008 00:18
Quote: "I wouldn't have learned theres a command like 'CLS'. Thats the first time I've ever seen it"


Seriously?

TDK_Man

Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 4th Apr 2008 14:03
Sorry, forgot to add, I wouldn't have learned theres a command like 'CLS' where you can set a color 'CLS RGB(R,B,G)'. When I saw that, I though for a sec it was a new command, until I went back to my code and had it everywhere, just never new about the RGB(R,B,G) bit.
Guardian
21
Years of Service
User Offline
Joined: 30th Sep 2003
Location:
Posted: 4th Apr 2008 19:43 Edited at: 4th Apr 2008 19:55
LOL, I think I'm cursed. First time I tried what was suggested it didn't work. So I got thinking, maybe if I removed the textured plain from the background, and that worked. However, now I don't have a map, just a bunch of sprites being saved. Any ideas why it wont save if there a 3d object on screen as well. Maybe I should add the plain loaded up before the sprites. So in order of loading sprites come after plain. Thx for all the help guys, I really appreciate it.

ok I tried something new out. Seems like my whole problem the complete time was the 3d object. set sprite 1,0,1 works, and paste sprite is not needed. So while the problem isn't solved, a few neat things have come to light. So the question is now placed, why does a 3d object completely override the sprite when using save image, also I noticed no matter what size the plain is, if its loaded, or any 3d object is loaded, it completely removed the sprites from the saved imaged, even if it doesn't cover all the sprites locations.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 5th Apr 2008 00:04
Try getting the 3D view right, then use Set Camera View 0,0,1,1. Then, paste your sprites, grab the image and then save it.

Use Set Camera View 0,0,Screen Width(),Screen Height() when you've saved it to reset the 3D screen. If nothing is moving 3D-wise you may be able to achieve a similar effect using Backdrop Off instead.

TDK_Man

Guardian
21
Years of Service
User Offline
Joined: 30th Sep 2003
Location:
Posted: 5th Apr 2008 04:05
no luck :-(
so I'm going to post demo code, hopefully it will help the process.


you will need a background image named world.jpg and a sprite image named hexr.jpg

Hopefully this helps thx
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 5th Apr 2008 08:09 Edited at: 5th Apr 2008 08:18
try this.



edit
code without other bits I left in.

Dark Physics makes any hot drink go cold.
Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 5th Apr 2008 22:15
I don't see why your having so many problems with this when it's already been solved more that once. Not only that, no one is listening to me when I say put a 1 on the end of get image for your screenshot to come out right.

Once again heres another WORKING! screenshot demo:


Not only that, but I've even attached the project.

Attachments

Login to view attachments
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 6th Apr 2008 21:48
@Guardian just merge your code with Sasuke`s.I try it and it save sprites into the image.@Sasuke, great job man!Very nice peace of code

Where is a will, there is a way.
Guardian
21
Years of Service
User Offline
Joined: 30th Sep 2003
Location:
Posted: 7th Apr 2008 18:02
yup finally got it working.

I took what howdo said, and experimented with it. Basically my issue was double sync. It would visually give me what I wanted, but not in a saved state. It turns out save image takes it from the stored buffer not the read buffer. So once I took out sync and used paste to post to the stored buffer, the problem went away.

Sasuke, I do appreciate the help. I had your code working, I just wanted to know why mine wasn't. After that experiment, the problem became obvious. Thank you all for your help.

That is why set sprite works, cause it saves to the stored buffer. You can get the same effect from using paste, with the big difference, of not having the png stored transperency being visiable, however your way works good if the built in darkbasic transperency works for jpg,bmp, but without your help as well, would never have figured it out.

So to sum it up, if you want sprites to save.
Paste
sync
save.

Thanks again everyone.

Login to post a reply

Server time is: 2024-11-25 06:49:51
Your offset time is: 2024-11-25 06:49:51