Home > Software engineering >  For big help!!!!! I extracted from essentially a database of information conversion after the header
For big help!!!!! I extracted from essentially a database of information conversion after the header

Time:11-15


//here is my extract image information from the database code

Char * pBuff=NULL;//to hold the bitmap memory space

Try

{

If (m_pRecordset!=NULL)
{
M_pRecordset - & gt; Close ();
}
//m_pRecordset - & gt; Open (bstrRecordset, m_pConnection GetInterfacePtr (), adOpenDynamic, adLockOptimistic, adCmdText);
M_pRecordset. CreateInstance (" ADODB. You ");
M_pRecordset - & gt; Open (" SELECT * FROM Table_1, "
_variant_t ((IDispatch *) m_pConnection, true),
AdOpenDynamic adLockPessimistic, adCmdText);

/* _bstr_t bstrSQL;
BstrSQL="select * from photo";
M_pRecordset. CreateInstance (__uuidof (you));
M_pRecordset - & gt; Open (bstrSQL, m_pConnection GetInterfacePtr (), adOpenDynamic, adLockOptimistic, adCmdText); */
Long DataSize.//in the database to read out the size of the bitmap
M_pRecordset - & gt; MoveLast ();//move to record in the end, ensure that the latest data
DataSize=m_pRecordset - & gt; Fields - & gt; The GetItem (" photo ") - & gt; ActualSize;//get the size of the bitmap fields

If (DataSize & gt; 0)//whether the bitmap fields empty
{

_variant_t TheValue;//store the data read

TheValue=https://bbs.csdn.net/topics/m_pRecordset-> the GetFields () -> the GetItem (" photo ") - & gt; GetChunk (DataSize);//read fields a
//TheValue=https://bbs.csdn.net/topics/m_pRecordset-> GetCollect (" photo ");
If (TheValue. N==(VT_ARRAY | VT_UI1))
{
PBuff=new char [DataSize + 1];
If (pBuff)
{
Char * buff=NULL;

SafeArrayAccessData (TheValue parray, (void * *) & amp; Buff);//put the bitmap data in the buff to
Memcpy (pBuff, buff, DataSize);//put the bitmap data in the pBuff

SafeArrayUnaccessData (TheValue parray);//release

M_pBMPBuffer=new char [DataSize + 1];//create a character array
Memcpy (m_pBMPBuffer pBuff, DataSize);

HBITMAP HBITMAP=NULL;//define a HBITMAP object, used to display a bitmap with
LPSTR hDIB, lpBuffer=m_pBMPBuffer;
LPVOID lpDIBBits;
BITMAPFILEHEADER bmfHeader;
DWORD bmfHeaderLen;

//get the bitmap header information
BmfHeaderLen=sizeof (bmfHeader);
//strncpy ((LPSTR) & amp; BmfHeader, LPSTR lpBuffer, bmfHeaderLen);
Memcpy (& amp; BmfHeader, lpBuffer, bmfHeaderLen);
//according to the information from the head judge whether the bitmap
If (bmfHeader bfType!=(* * (WORD) "BM"))
{
AfxMessageBox (_T (" this is not the bitmap!" ));
return;
}
//get the bitmap data
HDIB=lpBuffer + bmfHeaderLen;//move the pointer to the back of the header
BITMAPINFOHEADER & amp; BmiHeader=* (LPBITMAPINFOHEADER hDIB);
BITMAPINFO & amp; BmInfo=* (LPBITMAPINFO hDIB);
LpDIBBits=(lpBuffer) + ((BITMAPFILEHEADER *) lpBuffer) - & gt; BfOffBits;//offset bytes

//create a bitmap
CClientDC dc (this);
HBitmap=CreateDIBitmap (dc m_hDC, & amp; BmiHeader,
CBM_INIT, lpDIBBits, & amp; BmInfo, DIB_RGB_COLORS);


//display bitmap
CBitmap BMP.//variable defined bitmap
BMP. Attach (hBitmap);
BITMAP bm.//define a bitmap structure
BMP. GetBitmap (& amp; Bm);
The CDC dcMem.
DcMem. CreateCompatibleDC (GetDC ());//create a compatible DC
CBitmap * poldBitmap=(CBitmap *) dcMem. SelectObject (BMP);//the bitmap for equipment environment
CRect lRect;//define a region
CStatic * pstatic=(CStatic *) GetDlgItem (IDC_STATIC_pp);
Pstatic - & gt; GetClientRect (& amp; LRect);//to get control of the client area
LRect. NormalizeRect ();

Pstatic - & gt; GetDC () - & gt; StretchBlt (lRect lRect. Left, top, lRect. The Width (), lRect. Height (),
& DcMem, 0, 0, bm bmWidth, bm. BmHeight, SRCCOPY);//display bitmap
DcMem. SelectObject (& amp; PoldBitmap);//handle to the original for equipment environment
BMP. DeleteObject ();

/* CV: : Mat img.
If (HBitmapToMat (hBitmap, img))
{
DrawMat1 (img, IDC_STATIC_pp);
MessageBox (_T (" success "));
}
The else
{
MessageBox (_T (" failure "));
} */

}
}
}
}
Catch _com_error (e)

{
AfxMessageBox (e.D escription ());
//MessageBox (_T (" open data table failed!" ));

return;

}

After debugging the wrong information display
Bosses teach me

CodePudding user response:

c + + use ADO to access images


  • Related