Click here to Skip to main content
15,879,184 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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();
Posted

1 solution

You are converting the image to base64. You must either remove the conversion or convert it back at the other end.
 
Share this answer
 
Comments
Gokulnath007 5-Aug-11 8:46am    
Couldnt get your point?? Could you please explain with my code??
Gokulnath007 5-Aug-11 8:47am    
I have tried in removing the conversion of to base64 also, again the same thing happens.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900