How to make an image from an external source (PC)?

I would like to generate an image from a file saved on my PC, outside of the project. Is this possible, and how can it be done?

Are you saying you want to call display.newImage() or display.newImageRect() and pass in a path to a PNG or JPEG where the path is some arbitrary location on your PC and NOT in your app folder?

No you cannot.

SSK has a file library that will allow you to find and copy such files to your documents folder where you can then use them, but you cannot use them from an external source.

HOWEVER

If you’re a Windows user, you can can create a junction (soft-link) to a folder.

I do this all the time. i.e. I have a prototyping-art folder on my data drive called ‘images’, that I include in all my starter projects. To do this, I do the following:

  1. Keep the folder and its contents anywhere I want.
  2. Create a batch file with this in it:
rmdir images
mklink /j .\images D:\images
  1. Copy this batch file into all my starter projects at same level as main.cs
  2. Run the batch file once. (creates folder named images linked to shared image folder on data drive).
  3. Operate as usual.

Warning: When building projects, it will include ALL images in a folder, so don’t go crazy with files in this folder or you’ll make huge images when you build.

Also, you can have as many junctions as you want. This is how I use SSK. I have one copy on my machine and all projects create a junction pointing to it.

SSK:


Hello Hasty,

An an alternative to the solution as given by RoamingGamer, you can use plugins provided by StarCrunch. I have been using them on my Windows PC and Android devices. Below is some code snippets using one plugin “bytemap”,

local byteMap = require( "plugin.Bytemap" )
local texture1 = byteMap.loadTexture( {
    filename = "D:/Temp/icon.png", -- path to an image file
    format = "rgba",
    is_absolute = true, -- path above is absolute, instead of relative
} ) 
local image1 = display.newImage( texture1.filename, texture1.baseDir )

Please read the docs for all the options and functions, and importantly, the sample codes, (both are in the links below) as provided by StarCrunch.

(1) “bytemap” plugin to load image file from external source, outside the Solar2D sandbox,

(2) “asset reader” plugin to read file from external source (Android only),

(3) “tiny file dialog” plugin for a desktop native dialog box to select file or files and other functions (Desktop only)

1 Like

Hi guys. I now have this working. Thank you both for your help.