yglukhov / nimx

GUI library
MIT License
1.09k stars 75 forks source link

[Question] How does the AssetManaget work? #435

Closed mantielero closed 3 years ago

mantielero commented 4 years ago

Could you explain how the asset manager work?

I am trying to show an image using the full path, but I am failing (unless I put the image in the res folder).

Regard Jose M.

yglukhov commented 3 years ago

Asset manager is used to retrieve assets from the app resources, which are different things depending on your platform (on windows and linux this is res folder). To load an image from an arbitrary file path use imageWithContentsOfFile. To load image from arbitrary URL (including http://, https://, file://) use loadImageFromURL

mantielero commented 3 years ago

Thanks a lot. I managed to use imageWithContentsOfFile. I don't know why loadImageFromURL is not working for me. I am using similar code to your sample 3. Something like the following:

method init*(v: ImageSampleView, r: Rect) =
    procCall v.View.init(r)
    loadImageFromURL("file:///home/jose/src/pdf/Frances_01.pdf_FOLDER/original_thumbnails_256/68db24e7-fe4f-407b-89af-04bbbc7746f9-16.png") do(i: Image):
        v.httpImage = i
        v.setNeedsDisplay()

    #do(i: Image, err: string):
    v.image =  imageWithContentsOfFile("/home/jose/src/pdf/Frances_01.pdf_FOLDER/original_thumbnails_256/68db24e7-fe4f-407b-89af-04bbbc7746f9-16.png")
    v.setNeedsDisplay()

but b.httpImage is empty, and I don't know why.

yglukhov commented 3 years ago

Ah, turns out loadImageFromURL doesn't support file: scheme. PRs are welcome :)

EDIT: loadImageFromURL

yglukhov commented 3 years ago

The question is answered i suppose

mantielero commented 3 years ago

Yes it is. Thanks a lot mate.