0

I am trying to take BLOB type information from rows in a sqlite database and save them into picture files. They are all jpg files stored in the blob. When I attempt to loop through and create my jpeg files from the database blobs I get strange corrupted looking jpeg files that have some of the original data and shows the image, but there is alot of distortion too. I think it has to do something with the way the data is being handled from the DB. Anyways it's column six that contains the blobs, here is my code...

import sqlite3
cnt = 0
con = None
con = sqlite3.connect("C:\\my.db")
cur = con.cursor()
data = cur.execute("SELECT * FROM friends")
for item in data:
    cnt = cnt + 1
    a = open("C:\\images\\"+str(cnt)+".jpg", 'w')
    a.write(item[6])
    a.close()

It will create an image for each blob in each row, 902 to be exact, and the images actually are viewable, even of the correct picture, just some heavy distortion/corruption has been added and really mucks up the pictures? How can I create jpg picture files from each blob jpg file in my database using Python that aren't corrupted?

Thanks!

4

1 回答 1

1

以二进制模式写入文件:open("C:\\images\\"+str(cnt)+".jpg", 'wb').

于 2013-05-22T19:45:07.437 回答