I tried to show the memory image passed from unsigned char * in VC++ MFC Windows but I couldn't manage to see until now. Actually, it is working in the other SDK and functions for verification's purpose except display.
My code are as below and I hope some one will advise me to close the case as soon as possible.
Thanks in advance
My code are as below and I hope some one will advise me to close the case as soon as possible.
Code:
bool Dlg::Start()
{
LPCWSTR fileName = _T("C:\\test.bmp");
greyMemImage = LoadBMPFromFile(fileName);
// Display Image or Pattern here for Passing Data is correct
VECTOR_BYTE vecByte;
FILE* fpr = _wfopen(lpszFileName, L"rb");
if (fpr == NULL)
{
return false;
}
long lFileLength = _filelength(_fileno(fpr));
vecByte.resize(lFileLength, 0);
fread((void*)&(vecByte[0]), sizeof(unsigned char), lFileLength, fpr);
fclose(fpr);
fpr = NULL;
CDC* pDC = GetDC();
LPBYTE lpDIBBits = NULL;
LPBYTE pBWImageData = &(greyMemImage [0]);
int iColors = 0;
PBITMAPINFO pbitmapinfo = NULL;
PBITMAPINFOHEADER pbitmapinfoheader = NULL;
DWORD cbdwColorTable = 0;
int iMapMode = 0;
if (m_hbmImage != NULL)
{
DeleteObject (m_hbmImage);
m_hbmImage = NULL;
}
if (m_hdcImage != NULL)
{
DeleteDC (m_hdcImage);
m_hdcImage = NULL;
}
pbitmapinfo = (PBITMAPINFO)(pBWImageData + sizeof(BITMAPFILEHEADER));
pbitmapinfoheader = (PBITMAPINFOHEADER)(pBWImageData + sizeof(BITMAPFILEHEADER));
iColors = 1 << (pbitmapinfoheader -> biBitCount);
if (pbitmapinfoheader -> biBitCount >= 24)
cbdwColorTable = 0;
else
cbdwColorTable = (1 << (pbitmapinfoheader -> biBitCount)) * sizeof(RGBQUAD);
lpDIBBits = (LPBYTE)(pBWImageData + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + cbdwColorTable);
m_lImageWidth = (int)(pbitmapinfoheader -> biWidth);
m_lImageHeight = (int)(pbitmapinfoheader -> biHeight);
if (m_hdcImage == NULL)
m_hdcImage = CreateCompatibleDC(pDC -> m_hDC);
iMapMode = GetMapMode (pDC -> m_hDC); // Obtain mapping mode
SetMapMode (m_hdcImage, iMapMode); // Set memory DC mapping mode
if (m_hbmImage == NULL)
{
m_hbmImage = MyCreateBitmap(pDC -> m_hDC, pBWImageData, m_lImageWidth, m_lImageHeight, iColors);
}
SelectObject(m_hdcImage, m_hbmImage);
SetStretchBltMode((HDC)m_hdcImage, (int)HALFTONE);
StretchDIBits
(
(HDC)m_hdcImage, // handle of device context
(int)0, // x-coordinate of upper-left corner of dest. rect.
(int)0, // y-coordinate of upper-left corner of dest. rect.
(int)m_lImageWidth, // width of destination rectangle
(int)m_lImageHeight, // height of destination rectangle
(int)0, // x-coordinate of upper-left corner of source rect.
(int)0, // y-coordinate of upper-left corner of source rect.
(int)m_lImageWidth, // width of source rectangle
(int)m_lImageHeight, // height of source rectangle
(CONST VOID*)lpDIBBits, // address of bitmap bits
(CONST BITMAPINFO *)pbitmapinfo, // address of bitmap data
(UINT)DIB_RGB_COLORS, // usage
(DWORD)SRCCOPY // raster operation code
);
ReleaseDC(pDC);
InvalidateRect (NULL, TRUE);
return true;
}
Thanks in advance