Show image from url

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
monikadhingra
Posts: 19
Joined: Fri Dec 13, 2013 6:15 am

Show image from url

Post by monikadhingra » Fri Jan 24, 2014 7:44 am

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.

endernafi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 296
Joined: Wed May 02, 2012 12:23 pm
Location: New York
Contact:

Re: SHOW IMAGE FROM URL

Post by endernafi » Fri Jan 24, 2014 8:38 am

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.

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
Hope it helps...

Best,

~ Ender
~... together, we're smarter ...~
__________________________________________

macOS Sierra • LiveCode 7 & xCode 8

monikadhingra
Posts: 19
Joined: Fri Dec 13, 2013 6:15 am

Re: SHOW IMAGE FROM URL

Post by monikadhingra » Fri Jan 24, 2014 9:00 am

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.

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: SHOW IMAGE FROM URL

Post by Klaus » Fri Jan 24, 2014 12:56 pm

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

Post Reply

Return to “iOS Deployment”