Creating image in memory…

void CVirtualWndImg::InitDC(CDC &DC)
{
if(stVirtualImgWnd.iIsValid == 0)
{
stVirtualImgWnd.m_memDC.CreateCompatibleDC(&DC);
stVirtualImgWnd.m_bkBrush.CreateStockObject(WHITE_BRUSH);
stVirtualImgWnd.m_memDC.SelectObject(stVirtualImgWnd.m_bkBrush);
stVirtualImgWnd.iIsValid = 1;
}
}
void CVirtualWndImg::fnLoadImages(vector<CString> v_sImgPath, CDC &DC, vector<struct stReviewSet> &vReviewSet, double dThreshold)

{
HBITMAP hBitmap = NULL;
CBitmap cBitmapImg;
CString sPath;
CDC memDC;

memDC.CreateCompatibleDC(&DC);

int iRow = 0;
int iCol = -1, x, y;
double dDistance;

if(stVirtualImgWnd.iIsValid == 2)
{
if(stVirtualImgWnd.iImgCnt != v_sImgPath.size())
return FALSE;

for(int i = 0; i < stVirtualImgWnd.iImgCnt; i++)
{
if( (i == 0) || (i % stVirtualImgWnd.iImgPerRow) )
iCol++;
else
{
iRow++;
iCol = 0;
}

sPath = v_sImgPath[i];

hBitmap = (HBITMAP)::LoadImage(NULL, sPath, IMAGE_BITMAP,
stVirtualImgWnd.iImgMaxX, stVirtualImgWnd.iImgMaxY,
LR_LOADFROMFILE | LR_CREATEDIBSECTION);

if(hBitmap == NULL)
cBitmapImg.CreateCompatibleBitmap(&DC, stVirtualImgWnd.iImgMaxX, stVirtualImgWnd.iImgMaxY);
else
cBitmapImg.Attach(hBitmap);

memDC.SelectObject(&cBitmapImg);

x = stVirtualImgWnd.iGapBetweenImagesX*(iCol+1) + iCol*stVirtualImgWnd.iImgMaxX;
y = stVirtualImgWnd.iGapBetweenImagesY*(iRow+1) + iRow*stVirtualImgWnd.iImgMaxY;

stVirtualImgWnd.m_memDC.BitBlt(x, y, stVirtualImgWnd.iImgMaxX, stVirtualImgWnd.iImgMaxY, &memDC, 0, 0, SRCCOPY);

sscanf(LPCTSTR(vReviewSet[i].sDistance), “%lf”, &dDistance);

if(dDistance <= dThreshold)
{
memDC.SelectObject(&stVirtualImgWnd.m_bmpFailedSymbol);
stVirtualImgWnd.m_memDC.BitBlt(x + stVirtualImgWnd.iImgMaxX – 7, y + stVirtualImgWnd.iImgMaxY – 7, 7, 7, &memDC, 0,0, SRCCOPY);
}

DeleteObject(hBitmap);
cBitmapImg.DeleteObject();

}

stVirtualImgWnd.iIsValid = 3;

// DC.BitBlt(10, 30, stVirtualImgWnd.iWndMaxX, stVirtualImgWnd.iWndMaxY, &stVirtualImgWnd.m_memDC, 0, 0, SRCCOPY);
return TRUE;
}
else
{
return FALSE;
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: