Loading images async

Monkey Forums/Monkey Programming/Loading images async

Leginus(Posted 2013) [#1]
Hi all

After trawling through the forums I have found exactly what I was looking for (written by Mark) not so long ago. Unfortunately, it doesn't work with the new data buffer stuff and I cannot find any examples of the loading async in the help?

Have I missed it and could someone kindly point me in the write direction please. Thanks

Import mojo

Class MyApp Extends App Implements IOnLoadImageComplete

	Field image:Image

	Method OnCreate()
		LoadImageAsync( "http://www.monkeycoder.co.nz/img/logo/cute/monkey1.png",,,Self )
		SetUpdateRate 60
	End
	
	Method OnUpdate()
		UpdateAsyncEvents
	End
	
	Method OnRender()
		Cls
		DrawText "Hello World!",0,0
		If image DrawImage image,DeviceWidth/2,DeviceHeight/2
	End
	
	Method OnLoadImageComplete:Void( image:Image,path:String,source:IAsyncEventSource )
		If image Print "OK!" Else Print "ERR"
		Self.image=image
	End

End

Function Main()
	New MyApp
End



Markus(Posted 2013) [#2]
for me it works (html5 target,v72b)
Import mojo

Class MyApp Extends App Implements IOnLoadImageComplete

	Field image:Image

	Method OnCreate()
		LoadImageAsync( "http://www.monkeycoder.co.nz/img/logo/cute/monkey1.png",1,Image.MidHandle,Self )
		SetUpdateRate 60
	End
	
	Method OnUpdate()
		UpdateAsyncEvents
	End
	
	Method OnRender()
		Cls
		DrawText "Hello World!",0,0
		If image Then DrawImage image,DeviceWidth()/2,DeviceHeight()/2
	End
	
	Method OnLoadImageComplete:Void( image:Image,path:String,source:IAsyncEventSource )
		If image Then Print "OK!" Else Print "ERR"
		Self.image=image
	End

End

Function Main()
	New MyApp
End



Leginus(Posted 2013) [#3]
Interesting.
I get "BBThread is private" and the error highlights
Class AsyncImageLoaderThread Extends BBThread="BBAsyncImageLoaderThread"
in the module asyncimageloader.monkey

This is with version 75D

Interesting to know that it works for you, so I will try some other versions. Thx for the info


Leginus(Posted 2013) [#4]
Just to confirm. The code works in 74a but not onwards including 76a.I know these are experimental builds, but thought it was worth noting.


Markus(Posted 2013) [#5]
edit:
yes,can't get it to work in v76a for html5 or glfw :-(


AdamRedwoods(Posted 2013) [#6]
Class AsyncImageLoaderThread Extends BBThread="BBAsyncImageLoaderThread"

that's a bug. it should be "Extends Thread".

also, http image pathing only work with html5, flash. not glfw. you'll need to send an httprequest and build a small routine for that to work in glfw.