Drawing an image from a file

BlitzMax Forums/BlitzMax Beginners Area/Drawing an image from a file

Seb67(Posted 2009) [#1]
The online manual doesn't give an example for drawing an image from a file.

For now I have:

Img=LoadImage(ImgToLoad$)

ImgToLoad is a string that represents the imagefile, but once the image loaded, I don't know how to bring it on the screen.

I thing I need tu use the DrawImage command, but don't know what arguments I need.

Thanks.


Brucey(Posted 2009) [#2]
How's about something like this :
SuperStrict

Local Img:TImage = LoadImage("myimage.jpg")

Graphics 800, 600

While Not KeyDown(KEY_ESCAPE)
	Cls
	
	DrawImage Img, 100, 100
	
	Flip
Wend

End



Seb67(Posted 2009) [#3]
Graphics 800,600

.
.
.

Local Img:TImage=LoadImage(ImgToLoad$)
DrawImage Img,100,100
Flip


When compiling, I obtain: Unhandled Exception:Attempt to access field or method of Null object.

What represents the 100 ?


GfK(Posted 2009) [#4]
I thing I need tu use the DrawImage command, but don't know what arguments I need


BlitzMax Docs -> DrawImage
DrawImage( image:TImage,x#,y#,frame=0 )


I don't wish to sound rude, but what specific part of that is confusing you?


Seb67(Posted 2009) [#5]
The X and Y, I think it's the position of the image but I'm not shure.
I like to have examples, sorry but I'm in the Beginner's Area, so I think I'm rin the right place.


Brucey(Posted 2009) [#6]
Unhandled Exception:Attempt to access field or method of Null object.

My guess is that your image doesn't exist?


GfK(Posted 2009) [#7]
Yep.

X is the horizontal position (starting from the left), Y is vertical (starting from the top). So 0,0 represents the top-left corner of the screen. 100,100 means 100 pixels from the left, and 100 pixels from the top of the screen.

When compiling, I obtain: Unhandled Exception:Attempt to access field or method of Null object.
In this case the "Null object" is the image. For whatever reason, it hasn't loaded. Most likely cause would be either the specified file (in ImgToLoad$) was not found, or the image is in an unsupported file format.


Dabhand(Posted 2009) [#8]
Test it just after you load it:-

img = LoadImage("Media\gfx\blah.png")

If img = Null Then RuntimeError "Image does not exist!"


Dabz


Seb67(Posted 2009) [#9]
Thanks, you're right, it was a .gif. I thought this format is supported.
I simply converted it to a .jpg


xlsior(Posted 2009) [#10]
you need to have Graphics before loadimage -- loadimage will try to load it to the video memory, but if you haven't started a graphicsd moide yet there won't be a video context to attach it to.

If you wish to load images before opening a graphics screen, you'd have to load them as pixmaps (which resides in your normal system memory), which can then be converted to images after the graphcis context is created.


Jesse(Posted 2009) [#11]
@xlsior
that was fixed a while back. You can actually load images before setting the graphics mode. you just can't display them until you set the graphics mode.