Jump to content

QBasic/Images

From Wikibooks, open books for an open world

WARNING

[edit | edit source]

NONE of these functions work in IDEs other than QB64.

Simple image

[edit | edit source]
rem image_display
cls
Dim Image as long
x = 1000  'resolution
y = 1000
Image = _loadimage("TEST.jpg") 'loading the image
screen _newimage(x,y,32) 'putting screen sizes
_putimage (0,0),Image 'putting image

So you were most probably expecting miles of code. And there you have it, all you need to display an image in QB64!

So, what does this astoundingly simple piece of code even do?

A step-by-step explanation:

  1. We have DIMed our variable Image as a long value. This is because the image handle returned by the _loadimage function is a long value.
  2. x and y are our variables. They hold the values we need to put as the resolution. Thus ,for a 8n00 x 900 image, x = 800 ,y = 900.
  3. The image variable Image is next being put the handle values of the image "TEST.jpg". A healthy warning: Keep the image in the folder of the QB64 IDE. Or else, the function won't work!
  4. Next, we have resized the screen to fit the image. The newimage function requires three parameters, the resolution parameters and the color mode parameters. Here we have used 32-bit color modes, you can also use 256-bit pallete color modes.
  5. Lastly, we put the image using _putimage, which takes the Image variable (our image handle) as its parameter.

an example of images in qbasic

Secondary use of _newimage for setting screen details

[edit | edit source]

Well, you must be thinking, all these commands must be used in this exact same order. Nah, that isn't the case. You can use _newimage solo, to set the screen details, like shown below:

screen _Newimage(1000,1000,256)

This code sets the screen to a massive 1000 x 1000 resolution, with 256-bit palette color modes!