I am new in C++ .I am trying to load blob image which is stored in
.bin file from sql Database. That
.bin file store blob image in form of string like
BM6 ect(each
.bin have 3 to 4 char).
Here is
code(working) that save the blob
image(.bmp) in db
QPixmap p;
p.load(filename);
string a = "/root/QtApplication_1/file";
string b = boost::lexical_cast<std::string>(counter);
string c = ".bmp";
p.save(("/root/QtApplication_1/file"+boost::lexical_cast<std::string>(counter)+".bmp").c_str(),"BMP");
std::string d = a + b + c ;
std::ifstream blob_file;
blob_file.open(d.c_str(), std::ios_base::binary | std::ifstream::in);
driver = get_driver_instance();
con = driver->connect("localhost","","");
con->setSchema("BitmapImagesSchema");
prep_stmt = con->prepareStatement("Insert into bitmapImagesTable(`ID`,`ImageDir`,`ImagesBitMap`) values(?,?,?)");
prep_stmt->setInt(1,counter);
prep_stmt->setString(2,d.c_str());
prep_stmt->setBlob(3,&blob_file);
prep_stmt->executeQuery();
delete prep_stmt;
What I have tried:
Here is my
code(not working) that i am trying to get blob image from db and dispaly in QgraphicsView using pixmap
driver = get_driver_instance();
con = driver->connect("localhost","","");
con->setSchema("BitmapImagesSchema");
stmt = con-> createStatement();
std::istream *blobData;
res = stmt->executeQuery("select `ImagesBitMap` from bitmapImagesTable where `ID`='"+boost::lexical_cast<std::string>(counter)+"'order by `ID` DESC");
while(res->last()){
blobData = res->getBlob("ImagesBitMap");
break;
}
std::istreambuf_iterator<char> isb = std::istreambuf_iterator<char>(*blobData);
std::string blobString = std::string(isb,std::istreambuf_iterator<char>());
const char * image = blobString.c_str();
blobData->seekg(0,ios::end);
size_t imagesize = blobData->tellg();
cout<<"aaa="<<image<<"\n";
QPixmap p;
p.load(image);
if(!widget.graphicsView_2->scene()){
QGraphicsScene *scene = new QGraphicsScene(this);
widget.graphicsView_2->setScene(scene);
}
widget.graphicsView_2->scene()->addPixmap(p);
delete res;
delete stmt;
delete con;
Graphics view that is using pixmap is not display blob image on button click that execute above code.
The code for reading blob image i have taken from this
link
Here is blob data base that is
.bin file
image
Here is the out put of the
image varibale
cout<<"aaa="<<image<<"\n";
image
How to display blob image by using above code?