Hello All.
I'm trying to create jpegs out of data that is stored in a binary blob
format in an RDBMS (MS Access). I've tried writing the jpeg directly:
while not rs.EOF:
op = file(imgdir + "\\" + pic,"w")
print >op, rs.Fields[3].Value
##where rs.Fields[3].Value is the data in the blob from Access.
When I try to write out this file, the jpeg doesn't turn out.
Strangely, some of the colors partially render. You can see some
outlines and backgrounds, but the full picture doesn't show. Most
jpegs, however, show nothing (in an windows preview).
I then tried opening the image with PIL.Image, with something like
this:
cmd.CommandText = sql
rs=cmd.Execute()[0]
while not rs.EOF:
im = Image.open(StringIO.StringIO(rs.Fields[3].Value))
im.save("c:/projects/temp.jpg", 'JPEG', quality=90,progressive=1)
This is the error I get, I believe at the Image.open() call:
Traceback (most recent call last):
File "<string>", line 97, in run
File "C:\Python25\Lib\bdb.py", line 366, in run
exec cmd in globals, locals
File "C:\Projects\scripts\main.py", line 25, in <module>
xdb.doImageTbl(db)
File "C:\Projects\scripts\thunder.py", line 86, in doImageTbl
im = Image.open(StringIO.StringIO(rs.Fields[3].Value))
File "C:\Python25\lib\site-packages\PIL\Image.py", line 1916, in
open
raise IOError("cannot identify image file")
IOError: cannot identify image file
For a little further information, I was able to accomplish this task
in C#/.Net. A direct write to a file stream produced the exact jpeg
image. So I know the data is not corrupt. I would like to avoid using
the C#/.Net solution if possible.
Any ideas what I'm doing wrong? Any help would be greatly appreciated.
BTW, I'm using Python 2.5 and PIL 1.1.6 on a WinXp box.
Thanks,
jeh 5 6375
On Mon, 2007-07-16 at 18:57 +0000, ja*********@gmail.com wrote:
Hello All.
I'm trying to create jpegs out of data that is stored in a binary blob
format in an RDBMS (MS Access). I've tried writing the jpeg directly:
while not rs.EOF:
op = file(imgdir + "\\" + pic,"w")
print >op, rs.Fields[3].Value
##where rs.Fields[3].Value is the data in the blob from Access.
When I try to write out this file, the jpeg doesn't turn out.
Have you tried to open the file in "wb" mode?
HTH,
--
Carsten Haese http://informixdb.sourceforge.net
Have you tried to open the file in "wb" mode?
>
HTH,
--
Carsten Haesehttp://informixdb.sourceforge.net
The data is coming from a record set selection from the Access
database. I guess I could write the data to a temp file and open that
file handle with the "wb" mode. But, no, I haven't tried that.
jeh
On 2007-07-16, ja*********@gmail.com <ja*********@gmail.comwrote:
>Have you tried to open the file in "wb" mode?
The data is coming from a record set selection from the Access
database. I guess I could write the data to a temp file and
open that file handle with the "wb" mode. But, no, I haven't
tried that.
I think you missed the point.
When you want to write the binary data to a file, you must open
the destination file using "wb" mode. It's binary data, not
text data, so you have to open the output file in binary mode.
--
Grant Edwards grante Yow! Is my fallout shelter
at termite proof?
visi.com
On Jul 16, 3:23 pm, Grant Edwards <gra...@visi.comwrote:
On 2007-07-16, jayharva...@gmail.com <jayharva...@gmail.comwrote:
Have you tried to open the file in "wb" mode?
The data is coming from a record set selection from the Access
database. I guess I could write the data to a temp file and
open that file handle with the "wb" mode. But, no, I haven't
tried that.
I think you missed the point.
When you want to write the binary data to a file, you must open
the destination file using "wb" mode. It's binary data, not
text data, so you have to open the output file in binary mode.
--
Grant Edwards grante Yow! Is my fallout shelter
at termite proof?
visi.com
I did miss the point. I will give that a shot. Thanks Carsten and Grant
On Jul 16, 7:54 pm, jayharv...@gmail.com wrote:
On Jul 16, 3:23 pm, Grant Edwards <gra...@visi.comwrote:
On 2007-07-16, jayharva...@gmail.com <jayharva...@gmail.comwrote:
>Have you tried to open the file in "wb" mode?
The data is coming from a record set selection from the Access
database. I guess I could write the data to a temp file and
open that file handle with the "wb" mode. But, no, I haven't
tried that.
I think you missed the point.
When you want to write the binary data to a file, you must open
the destination file using "wb" mode. It's binary data, not
text data, so you have to open the output file in binary mode.
--
Grant Edwards grante Yow! Is my fallout shelter
at termite proof?
visi.com
I did miss the point. I will give that a shot. Thanks Carsten and Grant- Hide quoted text -
- Show quoted text -
This worked fantastically. Thanks! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Phil Palmieri |
last post by:
Im using md5 to encrypt and decrypt plain text, this works fine...
When i try to run the same function on a binary file, it does not
decrypt correctly. Is there a way to encrypt binary files...
|
by: David Stockwell |
last post by:
Hi,
I'd like to read the contents of a file into memory. The problem is that
this file is binary. I then want to store the whole thing in memory to a
database as a blob.
I have no problem...
|
by: Blaktyger |
last post by:
How can this be done? Images are stored in a LONGBLOB field. When I
try to display them, it prints out the binary data as it is...
Thank you
|
by: Fernando Chilvarguer |
last post by:
I'm having problems with a simple binary write.
The page is just supposed to write a JPEG back to the browser but the image
does not display (the "X" image shows).
Any help is appreciated. Here's...
|
by: Josema |
last post by:
Hi to all,
I have stored in a database some binary files (pdfs, and gif images), i
would like to know how could i show it, in internet explorer when a person
enters for instance in a textbox the...
| |
by: AlexCDM |
last post by:
Greetings;
I'm a (young) .NET developer and I have this problem: I'm building an
application (with C#) that creates PDF files. To display a JPEG image within
the PDF I need to copy the data from...
|
by: Lucas Cowald |
last post by:
Hi,
Using ASP and VBScript. How to convert JPEG image into a binary data? Is it
possible with a command from ASP / VBScript without having to put it into a
database first?
I want to take the...
|
by: Beginner |
last post by:
How do I convert JPEG images to binary files in ASP.NET? Please advice.
Thanks.
|
by: htres |
last post by:
Hello,
I'm new to programming and C#, so please bear with my ignorance!
I need to extract jpeg images and header data from a binary file.
The binary file is formatted with several fixed...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |