Copying a PGN File to the system.DocumentsDirectory

I have PGN files that are part of my project. I use them in setting pictures for some of my buttons. I would like to copy some of them to my system.DocumentsDirectory. If I load the PGN into display.save the picture will save as a JPG. Is there a way to identify a particular PGN file and copy it over maintaining its PGN characteristics ?

[import]uid: 22152 topic_id: 19898 reply_id: 319898[/import]

I believe at the present time you can only save as JPG and not as PNG. [import]uid: 52491 topic_id: 19898 reply_id: 77500[/import]

The code below will download a PNG file and save it as a PNG for use in a my project. The problem is I have to get it from a website. Is there a way to change the url to get the link to point to the PNG files that are loaded with my project. I want to do this so I can uses the following line:

display.newImageRect(“photo”… x … “.png”, system.DocumentsDirectory, 300, 300)

Any help would be appreciated.

[blockcode]
path = system.pathForFile(“photo”… x…".png", system.DocumentsDirectory )
local myFile = io.open( path, “w+b” )

– Request remote file and save data to local file
http.request{
url = “http://www.awebsite.com/apps/demo.png”,
sink = ltn12.sink.file(myFile),
}
[/blockcode] [import]uid: 22152 topic_id: 19898 reply_id: 77565[/import]

>>Is there a way to change the url to get the link to point to the PNG files that are loaded with my project. I want to do this so I can uses the following line:

display.newImageRect(“photo”… x … “.png”, system.DocumentsDirectory, 300, 300)<<

You dont need to use a URL to get the files that are bundled in your project.
You just refer to them directly and the app will find them in the resources folder.

If you have included photo9.png with your project, all you do is:

display.newImageRect(“photo”… x …".png",300, 300)

…where x = 9
[import]uid: 108660 topic_id: 19898 reply_id: 77571[/import]

That did not work when I tried the following experiment:
[blockcode]
mages[1] = display.newImageRect(“fire.png”, system.DocumentsDirectory, 300, 300)
images[1].x = display.contentWidth / 2
images[1].y = display.contentHeight / 2 -120
images[1].isVisible = true
images[1].alpha = 1.0
images[1].xScale = 1.0
images[1].yScale = 1.0
images[1].idx = i
localGroup:insert(images[1])
[/blockcode]
fire.png is bundled with my project
[blockcode]
WARNING: Failed to find image(fire.png)
Runtime error
…1449cmhc132pm9b6m0000gn/T/TemporaryItems/125/red.lua:562: attempt to index field ‘?’ (a nil value)
stack traceback:
[C]: ?
…1449cmhc132pm9b6m0000gn/T/TemporaryItems/125/red.lua:562: in function ‘_listener’
?: in function <?:501>
?: in function <?:215>
[/blockcode]

Any ideas? [import]uid: 22152 topic_id: 19898 reply_id: 77573[/import]

Why did you keep system.DocumentsDirectory in there?

try :

display.newImageRect(“fire.png”,300, 300) [import]uid: 108660 topic_id: 19898 reply_id: 77595[/import]

Yes that worked. [import]uid: 22152 topic_id: 19898 reply_id: 77610[/import]

Glad to see Jeff could help get this sorted :slight_smile:

Apologies for the above - I misunderstood what you were trying to do, although you explained it fine I for some reason took it to be related to the old capture screen bug. (I’d just responded to another post about it.)

Peach :slight_smile: [import]uid: 52491 topic_id: 19898 reply_id: 77700[/import]