Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED]Read Image from Android Storage in Qml



  • Hi
    I need to read an image from(ex: "/storage/sdcard0/DCIM/IMG_001.jpg") internal storage of android mobile to qml image source..I tried various ways..I could not do this.Please help me with ur ideas
    @Image{
    id: image
    source: "/storage/sdcard0/DCIM/IMG_001.jpg" //doesnt work
    }@


  • Moderators

    You should prepend file:// to the path.



  • hi
    thanks...it works fine..
    here is code..

    source: "file:///storage/sdcard0/DCIM/IMG_001.jpg"

    Thank u so much :-)



  • Hello.

    I'm trying to do exactly the same. However I get a totally black image back instead of my original image.

    Would you tell me if you had any similar problems, and if so, how you solved them?



  • Hi
    that should work absolutely fine...
    if not can u post ur code here...?

    Thanks



  • Thank you for your help.

    -I'm trying to set the source of the Image Element like that: @"file:///storage/emulated/0/Download/image.png"@ and the result is an absolutely black image.

    I have also tried using QQuickImageProvider rendering the image like that @ QPixmap pixmap("/storage/emulated/0/Download/image.png");@ but the same problem occurs.

    To my mainfest.xml I have this line added: <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

    EDIT:
    Oh, it seems like I figured it out. It works absolutely fine, but unfortunatelly not with the Download folder. I don't know what the problem is, there might be some extra permission reuired to acces the Download folder on Android. Or I don't know. -

    EDIT 2:
    This solution is perfect. My problem was originated from trying to use images with a too large resolution. If I set the sourceSize property, it scales down my image to the desired resolution, and it works perfectly. Thank you!



  • @beemaneni be aware that some QML components like Canvas, save files into local paths, so you should subtract the "file://" part.


Log in to reply