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.

DarkBASIC Professional Discussion / Loading and Pasting Images

Author
Message
ArcherSam
15
Years of Service
User Offline
Joined: 13th Mar 2011
Location: Florida, US
Posted: 24th Apr 2011 02:04
I'm trying to load an image file using the LOAD IMAGE and PASTE IMAGE command. The image file is located in C:\Desktop\Armsq2\Media Files\TSA Florida Logo.jpeg.

Here is the code I have tried so far.



Thanks!
thenerd
17
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 24th Apr 2011 02:24
What problem are you having? At first glance, this code seems like it would work.

ArcherSam
15
Years of Service
User Offline
Joined: 13th Mar 2011
Location: Florida, US
Posted: 24th Apr 2011 02:40
When I execute this code, I get a blank screen.
thenerd
17
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 24th Apr 2011 03:30 Edited at: 24th Apr 2011 03:34
Well, here is what I would suggest:

First of all, use the SYNC commands. these allow you to control when the game updates to the screen. By default, it will render whenever something is modified, which is not optimal for a game.

You can use sync by simply calling this function:

sync on

then, inside a loop, call sync. When using the sync commands, the game will update to the screen only when you call the sync command. This way, you can better control when you want to update.


Your code, using SYNC commands in a do/loop, would look like this:



the last part of the code draws the image to the screen, and then updates the screen, in an endless loop until you press the escape key.

ArcherSam
15
Years of Service
User Offline
Joined: 13th Mar 2011
Location: Florida, US
Posted: 24th Apr 2011 03:53
Thanks for the explanation on the SYNC commands, was confused previously about their functionality. I tried the code you provided but the image still did not show. Do you think the file type might be incompatible? I check the folder path and it is correct.
ArcherSam
15
Years of Service
User Offline
Joined: 13th Mar 2011
Location: Florida, US
Posted: 24th Apr 2011 03:57
LOL. The file extension was wrong. Windows Explorer continually showed the file type as *.jpeg but it was actually *.jpg . I might need to find a new file explorer! Thanks thenerd for your patience and time!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 24th Apr 2011 03:58
The file type should work fine.

You could try checking the loaded image file by using IMAGE EXIST(img).

Warning! May contain Nuts!
thenerd
17
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 24th Apr 2011 04:35 Edited at: 24th Apr 2011 04:35
Quote: "LOL. The file extension was wrong. Windows Explorer continually showed the file type as *.jpeg but it was actually *.jpg . I might need to find a new file explorer! Thanks thenerd for your patience and time!"

I thought that might be the case. With the proper extension, does it load now? If it still doesn't load, you might want to find a different image.

ArcherSam
15
Years of Service
User Offline
Joined: 13th Mar 2011
Location: Florida, US
Posted: 24th Apr 2011 04:56
Yup, the image loads now. Thanks!
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 24th Apr 2011 09:32 Edited at: 24th Apr 2011 09:32
Really it's not a good idea to have an absolute path like that. Put that picture in the same directory as your project file and code. And add a ,1 to the end to make it load the image without blurring it. There's also no need to clear the screen since there's nothing on it at the start anyway.



Or if you want to load it from a media directory (inside the project directory):



ArcherSam
15
Years of Service
User Offline
Joined: 13th Mar 2011
Location: Florida, US
Posted: 25th Apr 2011 03:05
How do I add a media directory inside the project directory? I just tried to import a media file using the Media toolbar and got the error: The media file is not under your project directory; subsequently it will not be stored in the final exe.
thenerd
17
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 25th Apr 2011 03:24
What he meant is that you should put the files in the same directory or a subdirectory of the EXE and project. Since the program first looks for files in its current directory, you don't need to include the full path that way.

ArcherSam
15
Years of Service
User Offline
Joined: 13th Mar 2011
Location: Florida, US
Posted: 25th Apr 2011 03:28 Edited at: 25th Apr 2011 03:28
Oh! So just put the folder "\Media Files" where the project file is. Got it. Now it makes sense. Was confused and unsure about how the DBPro interpreter compiles.

Login to post a reply

Server time is: 2026-07-18 06:41:29
Your offset time is: 2026-07-18 06:41:29