I’m trying to display images on canvas. The images are storage in a DB (mysql) in blob format. I read this post and I did the same but I’m getting an error when the blob data coming from the DB is converted to stream and then used by image class. The part of the code throwing the error is this:
When possible, you should try to send as much code as you can. Also send the entire error message (or at least the line number where the error occurred). Your code looks fine.
query = “select imagen from Pozo_Fotos where fecha_captura like ‘2014-03-27 20:24%’”
Run query on DB.
data = system.db.runQuery(query, “rkn”)
g = event.graphics
Verify query result
if len(data) >= 1:
bytes = data[0][0]
from javax.imageio import ImageIO
from java.io import ByteArrayInputStream
from java.net import URL
# USING THIS THE IMAGE IS DEPLAYED
#img_url = URL("http://viewik.ru/wp-kantent/uploads/2013/01/foto-0001.jpg")
#image = ImageIO.read(img_url)
# USING THIS I GOT THE ERROR
#bais = ByteArrayInputStream(bytes)
#image = ImageIO.read(bais)
#bais.close()
####BEGIN SCALED IMAGE####
scaledImage = image.getScaledInstance(640,-1,0)
event.graphics.drawImage(scaledImage, 0, 0, event.source)
####END SCALED IMAGE####[/code]
And this is the error:
[code]Traceback (most recent call last):
File “event:repaint”, line 36, in
I found the problem, I was saving the images on the DB using " MySQLdb.escape_string" and that was causing the problem. Now I’m saving the image in blob format whiout escape_string on the DB and the image is displayed using the same code I posted.