Last active
March 7, 2020 19:38
-
-
Save hal1932/4c9e1a7fab8482b41d0d0498a4d4f7aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sqlite3 | |
from contextlib import closing | |
from PySide2.QtCore import QByteArray, QBuffer, QIODevice | |
from PySide2.QtGui import QImage | |
import timeit | |
source = QImage('test.png') | |
# print(timeit.timeit(lambda: source.save('testaaa.png'), number=100)) | |
with open('test.png', 'rb') as f: | |
print(f) | |
data = f.read() | |
with open('test222.png', 'wb') as f: | |
f.write(data) | |
db_file = 'test3.db' | |
if os.path.isfile(db_file): | |
os.remove(db_file) | |
with closing(sqlite3.connect(db_file)) as conn: | |
cursor = conn.cursor() | |
cursor.execute('create table images (format text, bytes blob)') | |
for i in range(100): | |
cursor.execute('insert into images (format, bytes) values (?, ?)', ['PNG', data]) | |
conn.commit() | |
with closing(sqlite3.connect(db_file)) as conn: | |
cursor = conn.cursor() | |
def load(): | |
for i, (format, blob) in enumerate(cursor.execute('select format, bytes from images')): | |
image = QImage() | |
image.loadFromData(QByteArray(blob), format) | |
# print(len(image.bits()), image.format()) | |
image.save(f'test_out/test_out_{i}.png') | |
print(timeit.timeit(load, number=10)) | |
# load() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment