如何将这个Blob数据保存到数据库中? [英] How to save this blob data into database?

查看:622
本文介绍了如何将这个Blob数据保存到数据库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将此Blob数据保存到数据库中?我正在读取Qbytearray中的jpeg图像;但是在保存到数据库时,图像大小增加了一倍,而从数据库中检索时,文件已损坏.如何正确读取图像?

How to save this blob data into database?? I am reading the jpeg image in Qbytearray; But while saving to database, the image size is doubled and while retrieving from database, the file is being corrupted. How to read the image properly??

QByteArray buf=NULL;
originalPixmap =QPixmap();
originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
QString strfname;
strfname.sprintf("%d",c);
originalPixmap.save("C:\\Program Files\\image"+strfname+".jpeg","jpeg");
c++;
char Data;
QFile file("C:\\Program Files\\image"+strfname+".jpeg");
file.open(QIODevice::ReadOnly);
int len=file.size();
//buf=file.read(len);
buf=file.readAll();
file.close();
file.remove();
QSqlQuery query;
query.exec("INSERT INTO log (grab_date, ip_address, image,logged_user) "
"VALUES (?,?,?,?)");
query.bindValue(0,dd);
query.bindValue(1,address);
query.bindValue(2,buf.toBase64());
query.bindValue (3,hostname);
bool qry=query.exec();

推荐答案

您正在将映像转换为base64.您必须删除转换或将其转换回另一端.
You are converting the image to base64. You must either remove the conversion or convert it back at the other end.


这篇关于如何将这个Blob数据保存到数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆