And what is the type of bmpFile? I guess what I'm getting at here is that your real issue is more the problem of "How do I serialize a HBITMAP structure to an array of bytes and restore it." more than "how do I save it to the database". I think if you can take the database out of the picture for a moment and simply get the saving of the bitmap to an array of bytes in memory and re-loading working, you're going to be fine.
On Fri, Aug 29, 2008 at 2:38 PM, Jared Miller <[EMAIL PROTECTED]> wrote: > Yes I am able to do that. I fill out the BITMAPFILEHEADER and > BITMAPINFOHEADER information for the image, and then I do this: > > bmpFile.Write(&bitmapfileheader, sizeof(BITMAPFILEHEADER)); > bmpFile.Write(&bitmapinfoheader, sizeof(BITMAPINFOHEADER)); > bmpFile.Write(pbyBitmap, size); //pbyBitmap is the actual byte data > > This has worked correctly for me. I can load it from the file using > SHLoadDIBitmap(). > > That is the way I wrote it to a .bmp file. > > Jeffrey Becker wrote: >> Are you able to load and save the bitmap to a file? >> >> On Fri, Aug 29, 2008 at 2:13 PM, Jared Miller <[EMAIL PROTECTED]> wrote: >> >>> Hello, >>> >>> I am having trouble figuring out how to successfully write an image to the >>> SQLite database as a Blob, using C++. >>> >>> I have an HBITMAP that I would like to be able to store to and retrieve >>> from the DB. If I understand what I have read correctly, I am supposed to >>> write out the actual byte data to the DB. Here is what I have done so far. >>> >>> I pass in pbyBitmap as the bmBytes parameter to this function: >>> ImportPageImage(CPage* pPage, BYTE* bmBytes, DWORD bmSize), which calls the >>> code below. . . >>> >>> //prepare query >>> static const WCHAR tblInsertBlob[] = _T("Insert into [tblBlob] ([Data]) >>> values (?)"); >>> SQL_HANDLE blobHandle = m_pSqliteDB->PrepareQuery16(tblInsertBlob); //calls >>> sqlite3_prepare16() >>> >>> //bind blob >>> m_pSqliteDB->BindBlob(blobHandle, 1, (void *)bmBytes, bmSize); //calls >>> sqlite3_bind_blob (bmBytes is the pData param) >>> >>> Then I call StepQuery to execute it, and then I close the query. >>> sqlite3_bind_blob() returns SQLITE_OK when I run it, so it does not seem to >>> be encountering an error there. >>> >>> Something apparently gets written to the database, but it does not seem to >>> be correct. When I try to retrieve and display my image, it is all black >>> (which is how bitmaps look when there is no data). >>> >>> I think that the problem is coming from writing the BLOB to the database, >>> but I am not entirely sure. Just in case it is getting written properly and >>> I am not reading it from the database correctly, I will show you how I >>> pulled it from the DB. >>> >>> //prepare blob >>> sqlite3_blob* pBlob = NULL; >>> sqlite3_blob_open(m_sqliteDB, "main", "tblBlob", "Data", iBlobID, FALSE, >>> &pBlob); >>> >>> BLOB_HANDLE hBlob = pBlob; >>> int size = sqlite3_blob_bytes(hBlob); //works correctly, returns 998058 >>> BYTE* pBuffer = g_MemMgr.AllocDataBuffer(size); >>> >>> sqlite3_blob_read(hBlob, pBuffer, size, 0); //returns SQLITE_OK >>> sqlite3_blob_close(hBlob); >>> >>> I then try to make a bitmap out of the bytes in pBuffer, but when I do, it >>> turns out all black (as I mentioned earlier). >>> >>> Do I have the concept correct? And if so, what part of my current code >>> should I change to be able to use my DB to store image data? >>> >>> Thanks a lot. >>> >>> >>> >>> _______________________________________________ >>> sqlite-users mailing list >>> sqlite-users@sqlite.org >>> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users >>> >>> >> _______________________________________________ >> sqlite-users mailing list >> sqlite-users@sqlite.org >> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users >> >> >> > > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users