John Meisner wrote:
John Meisner wrote:
I've been working with images in python and wx and I've had success
going into & out of files and databases, and I can display an image from
a file. But for some reason I can't display an image that I have read
directly from a database field. I have usedf = open('picture.jpg')
pic = wx.ImageFromStream(f.write())Shouldn't this be
f = open('picture.jpg')
pic = wx.ImageFromStream(f)Hmm, that seems more elegant, but I was using f.write().
I don't see how f.write() could work at all.
You're write on two counts. (1) I was writing to a file, not opening a
wx.Image; and (2) I was using f.read(). Sorry for the screw up. (I was
posting from work, but my code was at home.)
If you try this, what do you get? Put your database data in data.
f = file('tmp.jpg', 'wb')
f.write(data)
f.close()f = file('tmp.jpg', 'rb')
file_image = wx.ImageFromStream(f, wx.BITMAP_TYPE_JPEG)
f.close()
print 'file image ok == ', file_image.Ok()io = cStringIO.StringIO(data)
data_image = wx.ImageFromStream(io, wx.BITMAP_TYPE_JPEG)
print 'data image ok == ', data_image.Ok()When you open tmp.jpg with a viewer, do you see an image? Are either
file_image or data_image ok? If something fails, what was the error message?
Can you post a small sample program?john
This is very close to what I was doing. I think the problem lay in the
one part I was taking for granted -- how I got the data out of the
database. It's a BLOB that comes back as an array. I couldn't pass the
array directly to StringIO(), so I was looping over the array and
writing it one index at a time. This worked when writing directly to a
file object, but, for whatever, reason, it didn't work with StringIO.
So I tried converting the array into a string first, then sending it to
a StringIO object. That worked! Thank goodness. I thought it was
going to be some obscure problem about converting to and from binary.
Thanks for all your help.
Sincerely,
Derek
···
On Monday 31 October 2005 11:30 am, Derek Croxton wrote:
On Saturday 29 October 2005 09:18 pm, Derek Croxton wrote: