Error at drawimage

Monkey Forums/Monkey Programming/Error at drawimage

DiabloV(Posted 2013) [#1]
Monkey Runtime Error : Memory access violation

wat is wrong ?

Import mojo

Global ecran_largeur:Int = 0
Global ecran_hauteur:Int = 0

global image1:Image

Function Main()
	Local base_de_mon_appli := New mon_application
End Function


Class mon_application Extends App
    

    Method OnCreate:Int()  ' est appelé lors de l'execution de l'appli
        SetUpdateRate 30
        
        ecran_largeur=DeviceWidth()
        ecran_hauteur=DeviceHeight()

	image1 = LoadImage("momo1.jpg")

        Return 0
    End Method
    
    
    Method OnUpdate:Int() ' appelé juste apres le onrender
        Return 0
    End Method


	Method OnRender:Int() ' appelé lors de modifs
		Cls
		'Print DeviceWidth()
		SetColor 128, 255, 128
		DrawText ecran_largeur+"   "+ecran_hauteur,10,10
		DrawImage (image1,20,20)
		Return 0
	End Method	

End Class



Raz(Posted 2013) [#2]
What's the file name for the above code? And do you have momo1.jpg in the directory filename.data ?


Midimaster(Posted 2013) [#3]
there are several reasons, why a image is not loaded.

First test, whether the image is NULL
	image1 = LoadImage("momo1.jpg")
If image1=NULL
     Print "ERROR: image not found"
Endif


For which target do you compile?

If the image is not loaded, it could be that the path is wrong or the image format is not supported on your target. Try a "png" instead of a jpg".


DiabloV(Posted 2013) [#4]
good view :


Temps �coul� 00:00:03.81
ERROR: image not found
Monkey Runtime Error : Memory access violation


but the image was in the same directory of my project.
and jpg or png does rhe same issue


i've try with a exemple image of the samples (blob.png) and then it works .

????????????


Shagwana(Posted 2013) [#5]
The image needs to be a .data folder. So if you main program filename is called "abc" then you need a folder called "abc.data".

Now you may also need to load it from the correct location as well....

image1 = LoadImage("monkey://data/momo1.jpg")


Note the above pre-fix to load from monkey data


Midimaster(Posted 2013) [#6]
Monkey is case sensitive: "momo.jpg" would not be the same like "Momo.jpg".

I ask again:

What target?

How is your app called?

What is the name of the apps' data folder?

Add a "Strict" command in the first line of your code!

Did you try an example from bananas? Or did you copy the sample image to your app.data folder and then tried to load it?

Did you create a new png from your image with a paint software?. Or did you simply try to rename it as png?

What are the dimensions of the image?

Create any new png image and try it with this image. Perhaps the file is corrupt.


DiabloV(Posted 2013) [#7]
Hi !



Monkey is case sensitive: "momo.jpg" would not be the same like "Momo.jpg". -> no it's good

I ask again:

What target? -> Glfw

How is your app called? -> je_debute

What is the name of the apps' data folder? je_debute.data

Add a "Strict" command in the first line of your code! -> ? if i do this, an error appears at Function Main():
illegal type expression

Did you try an example from bananas? Or did you copy the sample image to your app.data folder and then tried to load it?

Did you create a new png from your image with a paint software?. Or did you simply try to rename it as png? -> real png

What are the dimensions of the image? png: 211*209 jpg: 256*308

Create any new png image and try it with this image. Perhaps the file is corrupt. -> i do -> and work too



I changed the jpg format (momo1.jpg), and that's ok. (no progressive compression, baseline only works)


but the image appears "greenly" not the real colors ?


rIKmAN(Posted 2013) [#8]
if i do this, an error appears at Function Main():
illegal type expression

You need to make the Main() function return an Int when using Strict, the same way you are doing with OnCreate/OnUpdate/OnRender.
Function Main:Int()
    Local base_de_mon_appli := New mon_application

    Return 0
End Function



DiabloV(Posted 2013) [#9]
ok thanks !

Now, i get an another error :

"identifier 'MouseX' cannot be used in this way.

when i don't use Strict, all is ok.

Strict

Import mojo

Global ecran_largeur:Int = 0
Global ecran_hauteur:Int = 0

Global image1:Image

Global boutton_souris_gauche:Int =0


Function Main:int()
	New Jeu
	Return 0
End Function

Class Jeu Extends App
    
    Method OnCreate:Int()
    
        SetUpdateRate 30
        
        ecran_largeur=DeviceWidth()
        ecran_hauteur=DeviceHeight()
        
        image1 = LoadImage("mdrlogo2.png")
		If image1 = Null Error "Unable to load image"
	
      
    Return 0
    End
    
	Method OnRender:Int() ' appelé lors de modifs
	
		Cls
		If MouseDown(MOUSE_LEFT) Then boutton_souris_gauche=1 Else boutton_souris_gauche=0
		'Print DeviceWidth()
		SetColor 128, 255, 128
		DrawText ecran_largeur+"   "+ecran_hauteur,10,10
		DrawImage (image1,20,20)
		
		If boutton_souris_gauche=1 Then
		DrawText "ici",MouseX,MouseY
		End
	
	Return 0
	End Method	


    Method OnUpdate:int() ' appelé juste apres le onrender
    
    Return 0
    End Method

End



Volker(Posted 2013) [#10]
Try this:
DrawText("ici", MouseX(), MouseY())


DiabloV(Posted 2013) [#11]
ok

DrawText "ici",MouseX(),MouseY() work also.

Many hanks for your help, i continue to discover this great engine ;)



have you any idea why the image display not the real colors ?


rIKmAN(Posted 2013) [#12]
Because of this line:
SetColor 128, 255, 128
All drawing commands are affected by SetColor, so do a SetColor 255,255,255 before your DrawImage and it will be drawn normally.


DiabloV(Posted 2013) [#13]
Argh !!!

Thanks !!!

;)