Can you scale an image retrieved via loadremoteimage?

Does anybody know how to scale a remote image? I’ve done this to get the image:

[lua]day1WeatherIcon = display.loadRemoteImage(day1WeatherIconURL, “GET”, self, “Day 1 Weather Icon”, system.TemporaryDirectory, 25, screenHeight-50)[/lua]

I’ve then tried both day1WeatherIcon:scale(.5, .5) as well as day1WeatherIcon.xScale = .5 and get an error each time.

[text]
Runtime error
…Corona Projects/My Projects/Redneck Weather/main.lua:212: attempt to index global ‘day1WeatherIcon’ (a nil value)
stack traceback:
[C]: ?
…Corona Projects/My Projects/Redneck Weather/main.lua:212: in function <…corona projects weather>
[/text]
Using build 767, but don’t think it’s build specific. Any ideas?

Thanks! [import]uid: 64538 topic_id: 23593 reply_id: 323593[/import] </…corona>

I think your 1st statement is not working. Can you set any other property (like x, y, alpha etc.)? [import]uid: 19297 topic_id: 23593 reply_id: 94606[/import]

No, I cannot. The image does display for me at (25, screenHeight-50) per my first statement. Am I doing something wrong in the first statement? [import]uid: 64538 topic_id: 23593 reply_id: 94608[/import]

What does “self” mean in the first statement?

The syntax is
object = display.loadRemoteImage( url, method, listener [, params], destFilename [, baseDir] [, x, y] )

So “self” would be a listener which is probably not true here (guessing).

I’d suggest removing “self”. [import]uid: 19297 topic_id: 23593 reply_id: 94614[/import]

Thanks for trying to help!

According to the API docs, it’s the listener. However, I’m already inside a listener, so I called self instead. That said, I’ve tried using the example found in the API docs and adding scale, and I get the same error. Their example is as follows:

[lua]local function networkListener( event )
if ( event.isError ) then
print ( “Network error - download failed” )
else
event.target.alpha = 0
transition.to( event.target, { alpha = 1.0 } )
end

print ( "RESPONSE: " … event.response )
end

display.loadRemoteImage( “http://developer.anscamobile.com/demo/hello.png”, “GET”, networkListener, “helloCopy.png”, system.TemporaryDirectory, 50, 50 )[/lua]

So I tried assigning it to an object such as myImage = display.loadRemoteImage … and then using myImage.Scale but it fails too.
[import]uid: 64538 topic_id: 23593 reply_id: 94626[/import]

If you need to do some work in the listener, just create another function with a different name (e.g listnerLoadImage or something). Otherwise just put false instead of self. [import]uid: 19297 topic_id: 23593 reply_id: 94629[/import]

Thanks for tip! Any idea why I can’t scale the image in the Corona example though? [import]uid: 64538 topic_id: 23593 reply_id: 94634[/import]

  
local function networkListener( event )  
&nbsp; &nbsp; &nbsp; &nbsp; if ( event.isError ) then  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print ( "Network error - download failed" )  
&nbsp; &nbsp; &nbsp; &nbsp; else  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.target.alpha = 0  
 event.target:scale(2.0, 2.0)  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; transition.to( event.target, { alpha = 1.0 } )  
&nbsp; &nbsp; &nbsp; &nbsp; end  
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp; print ( "RESPONSE: " .. event.response )  
end  
&nbsp;  
display.loadRemoteImage( "http://developer.anscamobile.com/demo/hello.png", "GET", networkListener, "helloCopy.png", system.TemporaryDirectory, 50, 50 )  

does that work? [import]uid: 84637 topic_id: 23593 reply_id: 94737[/import]

Yes, that does work. So there must be a bug in my logic someplace that I’ll have to figure out. Thanks! [import]uid: 64538 topic_id: 23593 reply_id: 94801[/import]

What I have to do is call a function and put the scaling/effects in that function similar to your example above. Bottom line from my testing is that you MUST call a function to use effects!

Solved, and thanks again!! [import]uid: 64538 topic_id: 23593 reply_id: 94804[/import]