Dynamic displaying of local pictures in a directory

Hi all,

Using a template repeater, I am trying to display all pictures in a particular folder. Currently as I have it the template is simply a paintable canvas. On button click, the path to the all .jpg files that I want to display is found using glob, and then this information is passed to the template repeater dataset, and the paintable canvases display these pictures.

This method seems to display the images correctly, but it is terribly slow. I can only assume this is due to the repainting of 20-30 images.

Should I be using a different method of doing this? What would be the most efficient way? Should I be saving BLOB files instead of using paintable canvases?

Lastly, I been doing a very good job in freezing the designer window with scripts. Is there any way to force stop execution of scripts or go straight back into preview mode? It’s frustrating needing to force quit and potentially lose work because of an infinite loop or a dataset too big to hangle.

Thanks for the help,


Instead of reading a directory on your hard drive, could you possibly use the Ignition Image Management folder or are there just too many images?

Unfortunately there are just going to be too many images. The plan is to send an image to the server which can be seen on ignition whenever a reject on our bottling line occurs (so you can see an image of the bottle being under-filled, for example). So I don’t think the image management will cut it.

However, I have made a bit of headway with the problem. My main issue now seems to be the slow repainting of the images in each paintable canvas. Does anyone know how to store the images in BLOB files (or something similar) for quick repainting?

Below code is what we use to store PDF in the database.
You can just change the extension to jpg or whatever image format you use.
The pdfblob field is varbinary(max) in our MS SQL Server.
dd is a dropdown list that lists the PDF records in the database and loads them to a pdf viewer on the window.

path = system.file.openFile("pdf")
data = system.file.readFileAsBytes(path)
name = system.gui.inputBox("Enter a name for the file:","")
system.db.runPrepUpdate("insert into SYS_PDFs (docname, pdfblob) values (?, ?)",[name,data])
dd = event.source.parent.getComponent('ddPDFList')

Here a couple of ideas for you excerpted from code we use. One for a paintable canvas repaint event, the other for an image component text property. Each has its own merits. The second is interesting in that it can easily be modified if you want to just use a file and forego blob retrieval.

# blob to Paintable Canvas component via paint event
from javax.imageio import ImageIO
from java.io import ByteArrayInputStream
blob = system.db.runPrepQuery("select Image from %s where recId = ?" % table,[recId])
bytes = blob[0][0]
image = ImageIO.read(ByteArrayInputStream(bytes))
# use this in place of g.drawimage above if scaling is required
#scaledImage = image.getScaledInstance(1980,-1,0)
#g.drawImage(scaledImage, 0, 0, event.source)

# blob to Image component via file into image text property using HTML 
blob = system.db.runScalarQuery("SELECT Image FROM %s WHERE recId = %d" % (table,recId))
filename = system.file.getTempFile("jpg")
system.file.writeFile(filename, blob)
imageTextHTML = "<HTML><IMG SRC='file:///" + str(filename) + "' WIDTH=700 HEIGHT=700></IMG></HTML>"
event.source.parent.getComponent('Image').text = imageTextHTML

Thank you MMaynardUSG and markdobtech for your useful suggestions. I’ll attempt to implement your suggestions shortly and see how I go.