Need help imporing a jpeg into program

Can somebody tell me how i can imort a jpeg into my program?



center the picture?

is there a way that i can center the picture?

Centering images


In order to center an image you need to know the dimensions of the image. Let's assume you have the image in a variable called boxstring$. The height and width of the image is given by:

LET width$=boxstring$[9:10]
LET height$=boxstring$[13:14]
CALL bytepair(width$,width)
CALL bytepair(height$,height)

REM: find the mid point
ASK PIXELS xpix,ypix
LET midx=xpix/2
LET midy=ypix/2

BOX SHOW boxstring$ at midx-(width/2),midy+(height/2)

SUB bytepair(pair$,value)
LET byte1$=pair$(1:1)
LET value1=unpackb(byte1$,1,8)
LET byte2$=pair$(2:2)
LET value2=unpackb(byte2$,1,8)
LET value=value1+value2*256

Hope this helps

Big John


ok not to be mean i'm a little new to programming so could you explain the variables a little more. I'm trying to center my jpeg that 840* 540.

re: Huh?

Since you know the size of the image, you only need to know the size of your TrueBasic window. This is what Ask Pixel gets you, the width and height of the window. There are two ways to work with TrueBasic windows. You can use a SET WINDOW left,right,bottom,top and these values can be anything you want. Many will do SET WINDOW 0,1,1,0 for example. But if you want to manipulate images--especially bit-mapped images, then it can be more usefull to first ASK PIXEL xmax, ymax and then then Set Window 1,xmax,ymax,1. [Some would put the 1 at the bottom and the ymax at the top.]

Now you are ready to center you image. Use the middle portion of Big John's code for this. Find the center of the window--xmax/2, ymax/2 and then half of your image size--in your case 840/2 and 540/2.

The x-position of the image will then be at xmax/2-420 and the y-position will be ymax/2+270 (with my choice of coordinates, or ymax/2-270 is you use the alternative labeling of the vertical pixels.

The Box Show image$ at xmax/2-420,ymax/2+270 should work (the Box Show command positions a square image with the bottom left position specified.)

Not sure what the last part of Big John's code is about. ;-)


The last bit of code

The sub-routine called bytepairs calculates the decimal value of two bytes - hence byte pairs. The height and width values in boxstring$ are each represented by two bytes.

Big John

re:last bit of code

OK--this is actually useful general information. I take it that the boxstring$ for a image will always have the width and height encoded in the bytes indicated in the first part of the code.

While I tend to know the size of the graphics I'm using, I can imagine cases where this would have to be determined within the program. I have filed away this bit of code for future reference. Thanks.

Rick ;-)

Still error

same error as above this is what it is now

set window 0,839,0,539
CALL Read_Image ("JPEG", gamename$, "C:\Users\Tim\Desktop\Senior project-programming 2\Gamenamepage.jpeg$")

the photo is in a folder called...
Senior project-programming 2... and the tb bronze is in my applications folder on the desktop not in the program files.

Extension is wrong

You have .jpeg$ It should be .jpg


changed it so that its

set window 0,839,0,539
CALL Read_Image ("JPEG", gamename$, "C:\Users\Tim\Desktop\Senior project-programming 2\Gamenamepage.jpeg")

still error persists

"no such file. (9003) 2 in main program"

i have the 2000 version of tb Bronze if that helps

Thank you

Thanks all of you guys i got it working now so i can make fancy pages and get my programs up and running.

thank you very much


.jpg not .jpeg but be sure that is the actual name of the file, that is, the file name should be exactly "Gamenamepage.jpg". If that doesn't work, try making a new test graphics file and save it as a JPEG file and try and load that. Something may be amiss with the file you are trying to load.


Re: importing a jpeg filen...

Daranhiss ... You need to CALL the built-in subroutine:

CALL Read_Image ("JPEG", boxkeepstring$, filename$)

filename$ is the name of the jpeg file. boxkeepstring$ is the name of a string variable in your TB program. Regards ... Tom M


now i get the error "No such file. [9003] 2 in Main program" this is how i set it up
CALL Read_Image ("JPEG", gamepage$, gamenamepage$)
gamenamepage page is the name of the picture.

re: error?

Read the thread on gifs just below this one. There are specific examples there on how to call your file. You may need a full path to the file depending on how you are running the program.



thank you this will help make title pages a lot easier in a game