Purpose of the script: Take a byte array coming from a binary file and arrange it into an image. The byte array is being generated and written by Matlab. I know the values are making it into the script correctly.
Problem: I'm getting this attribute error on the display statement.
Caused by: org.python.core.PyException: Traceback (most recent call last):
File "event:actionPerformed", line 29, in
AttributeError: 'java.awt.event.ActionEvent' object has no attribute 'graphics'
Note: I can find a similar drawimage statement on example pages such as:
I also have almost this same code working on another page. The difference is that it generates a random number for each element (pixel) rather than reading it from a file, and the image is 100x100 instead of 10x10.
Check the code, I'm not even importing java.awt.event, unless its inherited.
So, where is this going wrong?
from java.awt.image import BufferedImage
from java.awt.image import Raster
from java.awt import Point
fred = system.file.readFileAsBytes('D:\ProjectsCurrent\Miles\VisionSystem\\test3.dat')
#This works to get the correct (0-255) value coming in.
for item in fred:
joe=item & 0xFF
image = BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
raster = image.getData();
sm = raster.getSampleModel();
writeRaster = Raster.createWritableRaster(sm,Point(0,0))
for i in range(10):
for j in range(10):
writeRaster.setSample(i, j, 0, bob[i*10+j])
print('made it to the end')
Yes, and Yes.
The reason I'm bringing it in via a button is because the automatic repaint on paintable canvas has a tendency to hang ignition if I screw it up badly enough.
Oops. Yeah, I need to pass the array to the paintable canvas before I try to display it.
That often happens if that script calls out across the network for any data it needs. That is bad. All necessary data should be brought to the component separately, preferably via background bindings, so the repaint event only needs to access properties locally.
Edit: by locally, I mean in memory. You are reading a file inside your repaint event. Not a good idea.
Yep, that did the trick. It took me a bit to figure out how to use .putClientProperty and .getClientProperty (I am most definitely NOT a Java person), but I have successfully turned a Matlab cat into a binary file and reassembled him in ignition. Thanks.