How do I add pictures into my program?

New to FreeBASIC? Post your questions here.
Post Reply
Mondoman712
Posts: 3
Joined: Nov 11, 2009 17:47

How do I add pictures into my program?

Post by Mondoman712 »

I know this sounds really noobish but i can't find instructions anywhere and i need to know how urgently.
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Post by Richard »

Take a look at the Bload command which can handle .BMP files.
Mondoman712
Posts: 3
Joined: Nov 11, 2009 17:47

Post by Mondoman712 »

i can't get the bload command to work
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

There are different ways to put images on the screen. Post your code and perhaps we can tell you what you are doing wrong.

-Vince
Mondoman712
Posts: 3
Joined: Nov 11, 2009 17:47

Post by Mondoman712 »

i dont have a code because i kept trying different things from different websites then deleting them when they didnt work
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

This loads a picture to the screen.

Code: Select all

ScreenRes 640,480,32
BLoad "myimg.bmp"
Sleep
BigBaddie
Posts: 40
Joined: Oct 10, 2009 10:08
Location: Space
Contact:

Post by BigBaddie »

I guess you want to load a picture at a specific point. lets say you want to
setup Screen 18 (640x480). and that the pic you want to load is 32x32,
here is the code:

Code: Select all

 dim myimage(4 * (32 * 32) + 4) as byte
 bload "yourimage.bmp", myimage(0)
 cls
 put(320, 200), myimage(0)
 sleep
and that you want to display it in the middle of the screen. any questions?
nkk_kan
Posts: 209
Joined: May 18, 2007 13:01
Location: India
Contact:

Post by nkk_kan »

It's better to use ImageCreate to allocate memory for an image rather than the math. Also, don't forget to ImageDestroy afterwards.

And if Bload fails, Check the return value.. Or maybe you're giving wrong filepath..
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Post by counting_pine »

Note: loading an image into an array, as in BigBaddie's method, is deprecated in FB, and I fully discourage it. I wouldn't be surprised if it caused weird errors or crashes.

For the best information, please check BLOAD's wiki page:
www.freebasic.net/wiki/KeyPgBload

Some examples are given there. They're not that well commented, but they are complete.
BigBaddie
Posts: 40
Joined: Oct 10, 2009 10:08
Location: Space
Contact:

Post by BigBaddie »

if bload doesnt work for you, i have a solution. after you compile your
code with FB, instead of clicking also the Run button in your IDE. just
head to the place you compiled your .exe file and double-click on it.
if it still doesnt work, check the image you provided in Bload exists.
roook_ph
Posts: 402
Joined: Apr 01, 2006 20:50
Location: philippines
Contact:

Post by roook_ph »

You can find picture loading programs in the examples directory. There is even a picture that is converted into hex format.
Post Reply