Hi,
I am trying to use images that I save in a ms SQLServer 2000 binary image field with python and of course display with wxPython. So far I can insert the images with:
sql = “insert into testing (myimage) Values (?)”
cur.execute(sql, (pypyodbc.Binary(data),))
I can retrieve the data with:
cur.execute('Set Textsize 2147483647 select myimage from testing where id = 1")
I found the above on google
But I can not figure out how to convert that data into a wxPython image. I have tried several ways without success.
cur.execute(‘select myimage from testing where id = 1’)
returned_data = cur.fetchone()
data = str(return_data[0])
or
data = StringIO(return_data[0])
img = wx.ImageFromData(Width,Height, data)
I get “invalid data buffer size”
It’s not the only thing I tried but I thought it best to ask as I see as a very normal procedure.
If anybody has a bit of code that would be very helpful - or maybe a link other than the wx.Image.
Thanks in advance,
Johnf
Hi,
I am trying to use images that I save in a ms SQLServer 2000 binary image field with python and of course display with wxPython. So far I can insert the images with:
sql = "insert into testing (myimage) Values (?)"
cur.execute(sql, (pypyodbc.Binary(data),))
I can retrieve the data with:
cur.execute('Set Textsize 2147483647 select myimage from testing where id = 1")
I found the above on google
But I can not figure out how to convert that data into a wxPython image. I have tried several ways without success.
cur.execute('select myimage from testing where id = 1')
returned_data = cur.fetchone()
data = str(return_data[0])
or
data = StringIO(return_data[0])
img = wx.ImageFromData(Width,Height, data)
I get "invalid data buffer size"
It's not the only thing I tried but I thought it best to ask as I see as a very normal procedure.
If anybody has a bit of code that would be very helpful - or maybe a link other than the wx.Image.
Hi John,
I don't know if this applies in your case, but nobody else has replied so I'll at least put it out there.
I import Rich Text Format documents, not quite the same as storing an image in a database but not necessarily so different either, depending on what format the images are in. (I don't know from pypyodbc, I have to admit.) The images are stored in a digitized (hex) format that is embedded in the document. Here's the code I use for converting the text I read from the RTF file into an image:
if self.image_type in [wx.BITMAP_TYPE_PNG, wx.BITMAP_TYPE_JPEG]:
# Create a StringIO stream from the HEX-converted image data
stream = cStringIO.StringIO(self.hex2int(txt))
# Now convert that stream to an image
img = wx.ImageFromStream(stream, self.image_type)
# If we were successful in creating a valid image ...
if img.IsOk():
(do whatever)
David
John,
What values do Width and Height represent in the “img = wx.ImageFromData(Width,Height, data)” statement?
http://www.wxpython.org/docs/api/wx-module.html#ImageFromData
As per that link, length of the data must be equal to (width * height * 3).
Sridhar
···
On Saturday, 6 June 2015 04:23:20 UTC+5:30, johnf wrote:
Hi,
I am trying to use images that I save in a ms SQLServer 2000 binary image field with python and of course display with wxPython. So far I can insert the images with:
sql = “insert into testing (myimage) Values (?)”
cur.execute(sql, (pypyodbc.Binary(data),))
I can retrieve the data with:
cur.execute('Set Textsize 2147483647 select myimage from testing where id = 1")
I found the above on google
But I can not figure out how to convert that data into a wxPython image. I have tried several ways without success.
cur.execute(‘select myimage from testing where id = 1’)
returned_data = cur.fetchone()
data = str(return_data[0])
or
data = StringIO(return_data[0])
img = wx.ImageFromData(Width,Height, data)
I get “invalid data buffer size”
It’s not the only thing I tried but I thought it best to ask as I see as a very normal procedure.
If anybody has a bit of code that would be very helpful - or maybe a link other than the wx.Image.
Thanks in advance,
Johnf
John,
What values do Width and Height represent in the “img = wx.ImageFromData(Width,Height, data)” statement?
This is expecting raw RGB bytes. So you need to tell it how large the image is, so it knows how to unpack the bytes.
-Chris
···
On Jun 9, 2015, at 8:23 PM, Sridhar sri.soham@gmail.com wrote:
http://www.wxpython.org/docs/api/wx-module.html#ImageFromData
As per that link, length of the data must be equal to (width * height * 3).
Sridhar
On Saturday, 6 June 2015 04:23:20 UTC+5:30, johnf wrote:
Hi,
I am trying to use images that I save in a ms SQLServer 2000 binary image field with python and of course display with wxPython. So far I can insert the images with:
sql = “insert into testing (myimage) Values (?)”
cur.execute(sql, (pypyodbc.Binary(data),))
I can retrieve the data with:
cur.execute('Set Textsize 2147483647 select myimage from testing where id = 1")
I found the above on google
But I can not figure out how to convert that data into a wxPython image. I have tried several ways without success.
cur.execute(‘select myimage from testing where id = 1’)
returned_data = cur.fetchone()
data = str(return_data[0])
or
data = StringIO(return_data[0])
img = wx.ImageFromData(Width,Height, data)
I get “invalid data buffer size”
It’s not the only thing I tried but I thought it best to ask as I see as a very normal procedure.
If anybody has a bit of code that would be very helpful - or maybe a link other than the wx.Image.
Thanks in advance,
Johnf
–
You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks guys - I some more information.
In the first few hundred bytes or so of the data there is a string ‘Foxpro Paint’. Googling I came up with the impression that the basic file is a BMP. The question now is how use this information from the database. David, I will try to use your code example and see what it produces.
Sridhar, I have played with so many different values for width and height - none work. There is something else I’m missing here.
Johnf
···
On Tue, Jun 9, 2015 at 8:23 PM, Sridhar sri.soham@gmail.com wrote:
John,
What values do Width and Height represent in the “img = wx.ImageFromData(Width,Height, data)” statement?
http://www.wxpython.org/docs/api/wx-module.html#ImageFromData
As per that link, length of the data must be equal to (width * height * 3).
Sridhar
On Saturday, 6 June 2015 04:23:20 UTC+5:30, johnf wrote:
Hi,
I am trying to use images that I save in a ms SQLServer 2000 binary image field with python and of course display with wxPython. So far I can insert the images with:
sql = “insert into testing (myimage) Values (?)”
cur.execute(sql, (pypyodbc.Binary(data),))
I can retrieve the data with:
cur.execute('Set Textsize 2147483647 select myimage from testing where id = 1")
I found the above on google
But I can not figure out how to convert that data into a wxPython image. I have tried several ways without success.
cur.execute(‘select myimage from testing where id = 1’)
returned_data = cur.fetchone()
data = str(return_data[0])
or
data = StringIO(return_data[0])
img = wx.ImageFromData(Width,Height, data)
I get “invalid data buffer size”
It’s not the only thing I tried but I thought it best to ask as I see as a very normal procedure.
If anybody has a bit of code that would be very helpful - or maybe a link other than the wx.Image.
Thanks in advance,
Johnf
–
You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
In the first few hundred bytes or so of the data there is a string 'Foxpro
Paint'. Googling I came up with the impression that the basic file is a
BMP. The question now is how use this information from the database.
David, I will try to use your code example and see what it produces.
Sridhar, I have played with so many different values for width and height
- none work. There is something else I'm missing here.
if there is a 'Foxpro Paint' in the file - it is not raw RGB data --
ImageFromData is NOT going to work.
wx.Image.LoadStream( cStringIO.StringIO(data) )
may be the way to go. YOu may need to specify the type, if it really is BMP.
wx.Image.LoadStream( cStringIO.StringIO(data), wx.BITMAP_TYPE_BMP )
I would maybe start by dumping the data into a file, and trying to load
that -- and/or try to load it into another image display program, so see
what type it is, and if it's corrupted, etc.
-CHB
···
On Wed, Jun 10, 2015 at 9:00 AM, John Fabiani <fabiani.john@gmail.com> wrote:
Johnf
On Tue, Jun 9, 2015 at 8:23 PM, Sridhar <sri.soham@gmail.com> wrote:
John,
What values do Width and Height represent in the "img =
wx.ImageFromData(Width,Height, data)" statement?
wxPython API Documentation — wxPython Phoenix 4.2.2 documentation
As per that link, length of the data must be equal to (width * height *
3).
Sridhar
On Saturday, 6 June 2015 04:23:20 UTC+5:30, johnf wrote:
Hi,
I am trying to use images that I save in a ms SQLServer 2000 binary
image field with python and of course display with wxPython. So far I can
insert the images with:
sql = "insert into testing (myimage) Values (?)"
cur.execute(sql, (pypyodbc.Binary(data),))
I can retrieve the data with:
cur.execute('Set Textsize 2147483647 select myimage from testing where
id = 1")
I found the above on google
But I can not figure out how to convert that data into a wxPython
image. I have tried several ways without success.
cur.execute('select myimage from testing where id = 1')
returned_data = cur.fetchone()
data = str(return_data[0])
or
data = StringIO(return_data[0])
img = wx.ImageFromData(Width,Height, data)
I get "invalid data buffer size"
It's not the only thing I tried but I thought it best to ask as I see as
a very normal procedure.
If anybody has a bit of code that would be very helpful - or maybe a
link other than the wx.Image.
Thanks in advance,
Johnf
--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov
Well I believe I have solved my problem.
It turns out that the image in the field is in fact a BMP. That helped a lot. I then discovered that if I removed the first 79 bytes from the data in the string returned from the data base that in fact the a correct bmp file was left. The first 79 bytes included 'FoxProPaint.Picture", ‘PBrush’ with lot of other bytes beyond the normal 128. I was lucky. Also the format of a BMP was available:
http://en.wikipedia.org/wiki/BMP_file_format
So now at least I have a real image file I can use.
Johnf
···
On Wed, Jun 10, 2015 at 9:00 AM, John Fabiani fabiani.john@gmail.com wrote:
Thanks guys - I some more information.
In the first few hundred bytes or so of the data there is a string ‘Foxpro Paint’. Googling I came up with the impression that the basic file is a BMP. The question now is how use this information from the database. David, I will try to use your code example and see what it produces.
Sridhar, I have played with so many different values for width and height - none work. There is something else I’m missing here.
Johnf
On Tue, Jun 9, 2015 at 8:23 PM, Sridhar sri.soham@gmail.com wrote:
John,
What values do Width and Height represent in the “img = wx.ImageFromData(Width,Height, data)” statement?
http://www.wxpython.org/docs/api/wx-module.html#ImageFromData
As per that link, length of the data must be equal to (width * height * 3).
Sridhar
On Saturday, 6 June 2015 04:23:20 UTC+5:30, johnf wrote:
Hi,
I am trying to use images that I save in a ms SQLServer 2000 binary image field with python and of course display with wxPython. So far I can insert the images with:
sql = “insert into testing (myimage) Values (?)”
cur.execute(sql, (pypyodbc.Binary(data),))
I can retrieve the data with:
cur.execute('Set Textsize 2147483647 select myimage from testing where id = 1")
I found the above on google
But I can not figure out how to convert that data into a wxPython image. I have tried several ways without success.
cur.execute(‘select myimage from testing where id = 1’)
returned_data = cur.fetchone()
data = str(return_data[0])
or
data = StringIO(return_data[0])
img = wx.ImageFromData(Width,Height, data)
I get “invalid data buffer size”
It’s not the only thing I tried but I thought it best to ask as I see as a very normal procedure.
If anybody has a bit of code that would be very helpful - or maybe a link other than the wx.Image.
Thanks in advance,
Johnf
–
You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I wouldn’t be suprised if Foxpro had some kind of exporter tool. Ah, old Foxpro.
···
On Wed, Jun 10, 2015 at 1:49 PM, Chris Barker chris.barker@noaa.gov wrote:
–
You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On Wed, Jun 10, 2015 at 9:00 AM, John Fabiani fabiani.john@gmail.com wrote:
In the first few hundred bytes or so of the data there is a string ‘Foxpro Paint’. Googling I came up with the impression that the basic file is a BMP. The question now is how use this information from the database. David, I will try to use your code example and see what it produces.
Sridhar, I have played with so many different values for width and height - none work. There is something else I’m missing here.
if there is a ‘Foxpro Paint’ in the file - it is not raw RGB data – ImageFromData is NOT going to work.
wx.Image.LoadStream( cStringIO.StringIO(data) )
may be the way to go. YOu may need to specify the type, if it really is BMP.
wx.Image.LoadStream( cStringIO.StringIO(data), wx.BITMAP_TYPE_BMP )
I would maybe start by dumping the data into a file, and trying to load that – and/or try to load it into another image display program, so see what type it is, and if it’s corrupted, etc.
-CHB
Johnf
–
You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov
–
On Tue, Jun 9, 2015 at 8:23 PM, Sridhar sri.soham@gmail.com wrote:
John,
What values do Width and Height represent in the “img = wx.ImageFromData(Width,Height, data)” statement?
http://www.wxpython.org/docs/api/wx-module.html#ImageFromData
As per that link, length of the data must be equal to (width * height * 3).
Sridhar
On Saturday, 6 June 2015 04:23:20 UTC+5:30, johnf wrote:
Hi,
I am trying to use images that I save in a ms SQLServer 2000 binary image field with python and of course display with wxPython. So far I can insert the images with:
sql = “insert into testing (myimage) Values (?)”
cur.execute(sql, (pypyodbc.Binary(data),))
I can retrieve the data with:
cur.execute('Set Textsize 2147483647 select myimage from testing where id = 1")
I found the above on google
But I can not figure out how to convert that data into a wxPython image. I have tried several ways without success.
cur.execute(‘select myimage from testing where id = 1’)
returned_data = cur.fetchone()
data = str(return_data[0])
or
data = StringIO(return_data[0])
img = wx.ImageFromData(Width,Height, data)
I get “invalid data buffer size”
It’s not the only thing I tried but I thought it best to ask as I see as a very normal procedure.
If anybody has a bit of code that would be very helpful - or maybe a link other than the wx.Image.
Thanks in advance,
Johnf
–
You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.