I am trying to get an image from a BLOB column in ignition. I have an image stored in MySQL in a blob column currently and am trying to display it with the paintable canvas in Ignition Vision 8.1. The code I am using currently is not working. Any help would be appreciated!
What does happen? Any errors in the console? Your approach there is still relatively inefficient, by the way - ImageIO's construction of the image isn't free and is going to be called often. It'd be better to cache the actual Image instance.
There aren't any errors in the console. When I put the designer into preview mode nothing shows up for the paintable canvas, and no errors are put into the console.
This may help simplify your efforts
Automation Professionals' Blob Server Module - 3rd Party Modules - Inductive Automation Forum
Not necessary for Vision. Vision can call a named query natively.
Pssst! Don't run a query inside a repaint event! Run the query as a named query binding on a custom property. Then the repaint event can just read the bytes. (And draw nothing when no bytes are present.)
For anyone that comes into this to check for solution. I ended up getting it to work by defining column and row index from sql query return. Also used @pturmel suggestion and placed the query inside a custom property.
This was very helpful to render an image blob from a database table, thanks! Is there a way to get the image rendered to resize to fit the canvas?
You can generate an AffineTransform
from the sizes of the image and the graphics space, then use this drawImage overload:
Or this one:
Perhaps more simplistically stated, the width and height parameters can be specified within the drawImage
call.
Example:
# graphics.drawImage(image, x, y, width, height, observer)
graphics.drawImage(image, 0, 0, event.width, event.height, event.source)
Note: If graphics.scale(dX, dY) is being used, the width and height variables will need to be explicit to the scaled size
Example:
dX = (event.width-1)/100.0
dY = (event.height-1)/100.0
graphics.scale(dX,dY)
# graphics.drawImage(image, x, y, width, height, observer)
graphics.drawImage(image, 0, 0, 100, 100, event.source)