如何从下面的代码中获取BLOB数据? [英] How to get the BLOB data from the below code?
本文介绍了如何从下面的代码中获取BLOB数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚使用lpBits存储二进制数据.但是在数据库中,我只能看到24bytes.如何转换找到图像的二进制数据.要将其存储在数据库中.
I have just used lpBits to store the binary data. But in database i see only 24bytes. How to convert the find the binary data of the image. To store it in the database.
HDC hScrDC = ::GetDC(NULL);
HDC hMemDC = NULL;
BYTE *lpBitmapBits = NULL;
int nWidth = GetSystemMetrics(SM_CXSCREEN);
int nHeight = GetSystemMetrics(SM_CYSCREEN);
hMemDC = ::CreateCompatibleDC(hScrDC);
BITMAPINFO bi;
ZeroMemory(&bi, sizeof(BITMAPINFO));
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth = nWidth;
bi.bmiHeader.biHeight = nHeight;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 24;
HBITMAP bitmap = ::CreateDIBSection(hMemDC, &bi, DIB_RGB_COLORS, (LPVOID*)&lpBitmapBits, NULL, 0);
HGDIOBJ oldbmp = ::SelectObject(hMemDC, bitmap);
::BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, 0, 0, SRCCOPY);
BITMAPFILEHEADER bh;
ZeroMemory(&bh, sizeof(BITMAPFILEHEADER));
bh.bfType = 0x4d42; //bitmap
bh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bh.bfSize = bh.bfOffBits + ((nWidth*nHeight)*3);
lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, bi.bmiHeader.biSizeImage);
CFile file;
char buffer[1000];
DWORD threadId;
int value = 10;
//hThread = CreateThread( NULL, 0, runThread, &value, 0, &threadId);
for(int c=0;c<10;c++)
{
sprintf_s(buffer,"D:\image%u.jpg",c);
CString sName(buffer);
LPCTSTR lpszName = sName;
if(file.Open(lpszName, CFile::modeCreate | CFile::modeWrite))
{
file.Write(&bh, sizeof(BITMAPFILEHEADER));
file.Write(&(bi.bmiHeader), sizeof(BITMAPINFOHEADER));
file.Write(lpBitmapBits, 3 * nWidth * nHeight);
file.Close();
Sleep(10000);
}
}
::SelectObject(hMemDC, oldbmp);
::DeleteObject(bitmap);
::DeleteObject(hMemDC);
::ReleaseDC(NULL, hScrDC);
推荐答案
您的问题是什么?
字符串D:\image%u.jpg
应该为D:\\image%u.jpg
What''s your question?
The stringD:\image%u.jpg
should beD:\\image%u.jpg
首先,位图(BMP)格式不会自动转换为jpeg(JPG).
BLOB 代表 B inary L arge OB ject,用于将二进制数据存储到数据库中.这可以是一切.因此,您可以将整个位图存储在数据库中.
您应该在数据库中打开到BLOB的流,然后将其写入文件中.
问候.
For the first: bitmap (BMP) format is not automatically converted to jpeg (JPG).
BLOB stands for Binary Large OBject, and is used to store binary data into a database. This can be everything. So you can store the whole bitmap in a database.
You should open a stream to your BLOB in database and write to it like into a file.
Regards.
这篇关于如何从下面的代码中获取BLOB数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文