Load external image

I use gui node to show image,I use image.load and gui.new_texture and gui.set_texture to load and show the image, but with the same filepath of different image content, it remains the first loaded image.Here is my code:

    local file = io.open(filepath, "rb")
if(file) then
	local data = file:read("*a")
	file:close()

	local img = image.load(data)
            if gui.new_texture(filepath, img.width, img.height, img.type, img.buffer) then
                    gui.set_texture(node, filepath)
            end
    end

I try to gui.delete_texture(filepath) before gui.new_texture, but it still don’t work

Are you sure that the file opens OK at all? If it does, does data actually contain anything? Do the logs provide any information? Adding some pprints would help narrow the issue down.

If the file opens OK and data is not empty, we will have to keep debugging.

It looks like you are storing the texture name to the same variable filepath used for opening the texture file on disk. I’m not sure if it fixes the issue, but you could try using a separate variable for the texture. E.g something like:

local tex_id = "my_gui_texture"
if gui.new_texture(tex_id, img.width, img.height, img.type, img.buffer) then
        gui.set_texture(node, tex_id)
end

I’m sure the file opens OK,and data is actually contain anything.I try to gui.delete_texture, and invoke gui.new_texture and gui.set_texture after 10 frames, It works.

Ok. Is there anything in the logs in the case where the texture is not set as expected?

No.There isn’t any log in the logcat