Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
how to load images from a folder on sdcard? — Gideros Forum

how to load images from a folder on sdcard?

keszeghkeszegh Member
edited November 2012 in General questions
Again, the title says it all. can you help me how can i do that?
optimally i would need a way to allow the user to select a folder (file picker) and then i want to load all the images in that folder.
maybe it is easy, i hope so. yet i don't know how can i do it. i need it on android, btw, so although this topic
http://www.giderosmobile.com/forum/discussion/comment/4791 seems helpful, it does not help me. do we need a plugin for that? in case yes, did anybody do such or similar android plugin already?
thanks

Likes: chipster123

+1 -1 (+1 / -0 )Share on Facebook

Comments

  • I don't think this is easy at the moment judging from what @atilim has said previously. Gideros will use the headers from a base resolution image to calculate scaling on a higher resolution image so, unless your folder has an sd version of the image plus the image at the actual size you want, it won't be possible. Not sure what Gideros would do if the sd version wasn't there at all. It also means your images would need to retain naming conventions per the scaling properties in your project.

    It may well be possible with plugins, bypassing Gideros' own routines when loading images. I'm also hopeful that Gideros will change so it never needs to touch the sd version when displaying higher resolution artwork as that should make what you want to do easier.

    As far as this thread below goes it looks like LuaFileSystem is integrated now so it should be possible to get directory listings etc:

    http://www.giderosmobile.com/forum/discussion/1204/gideros-support-for-file-system-search
  • keszeghkeszegh Member
    edited March 2015
    @moopf, perhaps you misunderstood my question, or i don't understand your answer, by sd i only meant that i want to reach a folder which is not in the apps own folder, but somewhere elsewhere on the sdcard. i do not ask about low and high resolution versions.
    on the other hand the link you sent about file system search may be helpful. also, in wip the gideros guide i found an empty section "11.1.2 Downloading images" which is very similar to what i need, except that i want to load from a local folder and not from an url. so it is sad that that section is not yet written.
  • moopfmoopf Guru
    edited November 2012
    No, I didn't misunderstand. I was explaining how Gideros treats images for scaling (and this could be pertinent to your question) which, unfortunately, also meant using the term sd in that context as well.
  • keszeghkeszegh Member
    edited November 2012
    I see, I don't use so far different scalings in the project, so i did not think about your problem, but it indeed may be - although when there is no file with the appropriate scaling then isn't it the case that gideros will generate one? so the app won't freeze or anything like that, only that it won't work efficiently.
    basically the problem would be solved if we can do 'rendertotexture', because then we can manually save different resolution variants of a loaded image. this i would need anyway as i need to downscale a lot the loaded images, basically i need thumbnails of them only, which is impossible now. of course it is possible to downscale but it will definitely degrade performance if i put 60 3mb images on the screen with a very small scaling instead of putting only their lo-res thumbnails on the screen.

    so rendertotexture is the solution as far as i see.

    also i wrote a very simple example to get an image from a common directory on the sdcard and save it in the apps directory - using the lua and gideros documentations this is easy to do indeed, yet for a beginner as i am it may be useful.
    local f = io.open("/sdcard/DCIM/imagetoload.jpg", "r")
    local t = f:read("*a")
    f:close()
     
    local outf=io.open("|D|savedimage.jpg","w")
    outf:write(t)
    outf:close()
     
    local b = Bitmap.new(Texture.new("|D|savedimage.jpg"))  
     
    b:setAnchorPoint(0.5, 0.5)
    b:setPosition(160, 240)
    stage:addChild(b)
    the lua file system plugin is capable to do a file-picker - if somebody has one (for android), please share - and together with this code it is basically possible what i asked for in the first post, except the downscaling, where rendertotexture will help, when it becomes available.

    ps: a simple luafilesystem example that can be extended to a file-picker:
    require("lfs")
    workingdir="/sdcard/DCIM/"
    print(workingdir.." contains:")
    for file in lfs.dir(workingdir) do
        if lfs.attributes(workingdir..file,"mode") == "file" then print("file: "..file)
        elseif lfs.attributes(workingdir..file,"mode")== "directory" then print("dir: "..file)
        end
    end
    thanks for your help
  • atilimatilim Maintainer
    Accepted Answer
    @keszegh you already found that you can use absolute paths that begins with "/" or "C:/", "D:/" (in windows).

    If you want to use images with suffix like @2x or @4x, also the base image should be at the same folder. And I'm planning to lift this restriction according to @moopf's suggestion.

    Likes: moopf

    +1 -1 (+1 / -0 )Share on Facebook
  • is it possible to use a standard file picker at least on desktops? probably it would be easy to add this feature via qt, i guess.
  • @keszegh
    Well, i'm thinking on adding that too. Also copy to clipboard, and such

    Likes: keszegh, pie

    +1 -1 (+2 / -0 )Share on Facebook
Sign In or Register to comment.