Hi,
I want to show image from url but unable to do.
If we want to load local image than thats possible like
set the filename of image "image" of me to
but not sure how to download image from url and show .
Regards,
Monika.
Show image from url
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 296
- Joined: Wed May 02, 2012 12:23 pm
- Location: New York
- Contact:
Re: SHOW IMAGE FROM URL
Monika hi,
There are many methods to accomplish this.
Two of them are:
1.
The easiest one;
_set the filename of image "image" of me to "http://www.example.com/myImage.png"
Unfortunately, this method is blocking;
that is, your app will halt and won't respond to the user interactions until all images are loaded this way.
Another withdraw of this method is that every time you go that card or open your app, the images will be assigned from start.
It won't keep cache and your app will always need an active internet connection.
2.
A more subtle but way-harder method is;
well, it's pretty hard at least it was for me.
You have to crawl all images,
check whether it exists,
if missing then download appropriate file via
libUrlDownloadToFile or put url("binfile:" & myUrl) to url("binfile:" & myLocalImage.
You should do this with a timed crawler not to block the app.
This is just a small portion of my code, you may wanna inspect it;
beware that this is not a complete script, missing many crucial parts; it's just an example.
Hope it helps...
Best,
~ Ender
There are many methods to accomplish this.
Two of them are:
1.
The easiest one;
_set the filename of image "image" of me to "http://www.example.com/myImage.png"
Unfortunately, this method is blocking;
that is, your app will halt and won't respond to the user interactions until all images are loaded this way.
Another withdraw of this method is that every time you go that card or open your app, the images will be assigned from start.
It won't keep cache and your app will always need an active internet connection.
2.
A more subtle but way-harder method is;
well, it's pretty hard at least it was for me.
You have to crawl all images,
check whether it exists,
if missing then download appropriate file via
libUrlDownloadToFile or put url("binfile:" & myUrl) to url("binfile:" & myLocalImage.
You should do this with a timed crawler not to block the app.
This is just a small portion of my code, you may wanna inspect it;
beware that this is not a complete script, missing many crucial parts; it's just an example.
Code: Select all
local imageCounter
on fillViewImages
local tBaseUrl, tUrl
local tFilename, tFolders
local tFilesize
local tAsset, tPlantID
local tAspectRatio, tLoc
if imageCounter is empty then put 1 into imageCounter
lock screen
try
set the itemDel to "|"
set the lineDel to "`"
put item 1 of line imageCounter of viewData into tPlantID
put item 4 of line imageCounter of viewData into tBaseUrl
put tBaseUrl into tFilename
put tBaseUrl into tUrl
replace "../" with getLoc() in tFilename
replace "../" with "http://www.example.com/" in tUrl
put tFilename into tFolders
replace getLoc() with empty in tFolders
set the itemDel to "/"
delete item -1 of tFolders
set the itemDel to "|"
setFolders tFolders
if there is not a file tFilename then
if checkConnection() then
put url("http://www.example.com/mobileApp/getFileSize.php?theFile=" & tBaseUrl) into tFilesize
libUrlDownloadToFile tUrl, tFilename
if there is not a file tFilename then
put getLoc("imageAssets") & "no_photo.png" into tFilename -- not downloaded
else if getFileSize(tFilename) <> tFilesize then
delete file tFilename
put getLoc("imageAssets") & "no_photo.png" into tFilename -- faulty download
end if
else
put getLoc("imageAssets") & "no_photo.png" into tFilename -- no connection
end if
end if
if (tFilename is not (getLoc("imageAssets") & "no_photo.png")) and (getFileSize(tFilename) < 10000) then
delete file tFilename
put getLoc("imageAssets") & "no_photo.png" into tFilename -- faulty download
end if
put the long id of image ("plantImage" & imageCounter) into tAsset
set the filename of tAsset to tFilename
put the loc of tAsset into tLoc
put the formattedWidth of tAsset / the formattedHeight of tAsset into tAspectRatio
if (((the height of templateImage) * tAspectRatio) <= the width of templateImage) then
set the width of tAsset to ((the height of tAsset) * tAspectRatio)
end if
set the loc of tAsset to tLoc
set the showBorder of tAsset to true
set the cPlantID of tAsset to tPlantID
end try
unlock screen
if ((imageCounter >= min(the number of images of viewContent, (contentMaxRow * contentMaxCol))) or \
((the milliseconds - item 1 of viewStatistics) > (10 * 1000))) then
reset templateImage
put true into isContentReady
if isMobile then iphoneActivityIndicatorStop
lock screen for visual effect
set the layer of button "shade" to bottom
unlock screen with visual effect "dissolve fast"
setScroller
set the layer of image "grass" to top
set the moveSpeed to round(screenWidth / 2)
move image "grass" relative (0 & comma & -(the height of image "grass")) without waiting
put 1 into imageCounter
else
add 1 to imageCounter
send "fillViewImages" to me in 1 ticks
end if
end fillViewImages
Best,
~ Ender
~... together, we're smarter ...~
__________________________________________
macOS Sierra • LiveCode 7 & xCode 8
__________________________________________
macOS Sierra • LiveCode 7 & xCode 8
-
- Posts: 19
- Joined: Fri Dec 13, 2013 6:15 am
Re: SHOW IMAGE FROM URL
Hi Ender,
I am working on one rss app ,i need one developer to work on same ,ready to pay him,you or any other developer if interested please let me know,work is not tough.
Regards,
Monika.
I am working on one rss app ,i need one developer to work on same ,ready to pay him,you or any other developer if interested please let me know,work is not tough.
Regards,
Monika.
Re: SHOW IMAGE FROM URL
Hi Monika,
please only ONE thread per problem, thank you!
http://forums.runrev.com/phpBB2/viewtop ... =4&t=18885
I deleted the duplicate of this thread form the "Complete beginners" forum.
Best
Klaus
please only ONE thread per problem, thank you!
http://forums.runrev.com/phpBB2/viewtop ... =4&t=18885
I deleted the duplicate of this thread form the "Complete beginners" forum.
Best
Klaus