How to download an image in corona SDK?

By | January 26, 2012

Downloading an image in corona is really easy.
Check out the example.


	module(..., package.seeall)

	_W = display.contentWidth;
	_H = display.contentHeight;

	function new()
		local grp = display.newGroup();
		local myImage;

		local function networkListener( event )
			if ( event.isError ) then
					print ( "Network error - download failed" )
			else
					myImage = display.newImage( "helloCopy.png", system.TemporaryDirectory, 60, 40 )
					myImage.alpha = 0
					transition.to( myImage, { alpha = 1.0 } )

			end

			print ( "RESPONSE: " .. event.response )
				grp:insert(myImage)
	end

	network.download( "http://developer.anscamobile.com/demo/hello.png", "GET", networkListener, "helloCopy.png", system.TemporaryDirectory )

	return grp;

	end

Check the console to see where the downloaded file is saved.

Download the complete source code from here.

Leave a Reply

Your email address will not be published. Required fields are marked *