Hello, thank you.
I have try wxBITMAP_TYPE_PNG and don’t work.
Sorry, i forgot code ...
Code: Select all
wxString wxMemoryBufferToString(const wxMemoryBuffer& buffer)
{
wxString mystring(buffer, wxConvUTF8);
return mystring;
}
Yes this is related to your other posts regarding wxSQLite.
It is old problem for me.
As i see in minimal the code is as bellow ...
Code: Select all
db.ExecuteUpdate("create table bindata(desc char(10), data blob);");
int binSize = 256;
unsigned char* binData = new unsigned char[binSize];
for (i = 0; i < binSize; i++)
{
binData[i] = i;
}
wxSQLite3Statement stmt = db.PrepareStatement("insert into bindata values ('testing', ?);");
stmt.Bind(1, binData, binSize);
stmt.ExecuteUpdate();
cout << "Stored binary Length: " << binSize << endl;
q = db.ExecuteQuery("select data from bindata where desc = 'testing';");
const unsigned char* pbin = binData;
if (q.NextRow())
{
int blobLen;
const wxString columnName(wxS("data"));
pbin = q.GetBlob(wxString(wxS("data")),blobLen);
cout << "Retrieved binary Length: " << blobLen << endl;
}
for (i = 0; i < sizeof binData; i++)
{
if (pbin[i] != i)
{
cout << "Problem: i: ," << i << " bin[i]: " << pbin[i] << endl;
}
}
q.Finalize();
delete[] binData;
How to make a file, not only an image , but other types, like .doc or .pdf to binary, with safe way and then store in db?
As i see in net the codes bellow maybe are working for me...
Code: Select all
bmp to text
#include <stdio.h>
int main(int argc, char*argv[]){
FILE *ptr_bmp_in;
FILE *ptr_text_out;
int c;
ptr_bmp_in=fopen("panda_input.bmp","rb");
ptr_text_out=fopen("panda_to_text.txt","w");
if(!ptr_bmp_in)
{
printf("Unable to open file\n");
return 1;
}
while((c=fgetc(ptr_bmp_in)) != EOF)
{
for(int i=0;i<=7;i++)
{
if(c&(1<<(7-i)))
{
fputc('1',ptr_text_out);
}
else
{
fputc('0',ptr_text_out);
}
}
}
fclose(ptr_bmp_in);
fclose(ptr_text_out);
printf("Writing done\n");
return 0;
}
and text to bmp
#include <stdio.h>
char bytefromtext(unsigned char* text)
{
char result = 0;
for(int i=0;i<8;i++)
{
if(text[i]=='1')
{
result |= (1 << (7-i));
}
}
return result;
}
int main(int argc, char*argv[]){
FILE *ptr_txt_in;
FILE *ptr_bmp_out;
unsigned char buf[8];
int c;
int j = 0;
ptr_txt_in=fopen("panda_to_text.txt","r");
ptr_bmp_out=fopen("panda_output.bmp","wb");
if(!ptr_txt_in)
{
printf("Unable to open file\n");
return 1;
}
while((c=fgetc(ptr_txt_in)) != EOF)
{
buf[j++] = c;
if(j==8)
{
fputc(bytefromtext(buf),ptr_bmp_out);
j=0;
}
}
fclose(ptr_txt_in);
fclose(ptr_bmp_out);
printf("Writing done\n");
return 0;
}
I must find some time to check out...
Thank you.
Jim