I need to save an wxBitmap to SQLite to a blob type.

I need to save an wxBitmap to SQLite to a blob type without save to disk or on some media.
i have mybitmap as wxBitmap;
First must convert to wxImage and get data.
Second convert to string and that way to store to blob column of database.
But wxMessageBox(sName) gives nothing.
What i am doing wrong?

1
2
3
4
5
6
7
8
9

wxImage img=mybitmap.ConvertToImage();
unsigned char* data=img.GetData();
int datalength=img.GetWidth()*img.GetHeight()*3;
char *myBuffer = (char *)data;
std::string sName(myBuffer);
wxMessageBox(sName);

Last edited on
On line 6, you are creating a std::string as far as the first zero value in the buffer. NOT all the char array; just as far as the first zero value in it.

That's how the string constructor works. Otherwise how does it know where the end of your char array is? You're passing it a c-string, and a c-string finishes at the first zero value.

There is another constructor you can use in which you tell the string how many char it should read:
std::string sName(myBuffer, number_of_char_to_read);
Don't get the number wrong. Can you not just save the char data directly, without converting to string?

Can you not just save the char data directly, without converting to string?

How i can do that?
In sql must have
update mytable SET blob_column='??????' WHERE id='1'
or something like that.
How must construct query?
Last edited on
Registered users can post here. Sign in or register to post.