bool IGFrameManager::Cut(LPCWSTR pcwGuid) { IGSmartPtr <IGFrame> spFrame; if (!GetFrame(pcwGuid, spFrame)) return false; CxImage *pCxLayer = spFrame->GetWorkingLayer(); if (!pCxLayer) return false; RECT rcSel; if (pCxLayer->SelectionIsValid()) pCxLayer->SelectionGetBox (rcSel); else{ rcSel.bottom = 0; rcSel.left = 0; rcSel.top = pCxLayer->GetHeight(); rcSel.right = pCxLayer->GetWidth(); } m_spClipboardLayer = new IGLayer(NULL); m_spClipboardLayer->Create (rcSel.right - rcSel.left, rcSel.top - rcSel.bottom, 24); m_spClipboardLayer->AlphaCreate(); pCxLayer->AlphaCreate(); RGBQUAD qGray; qGray.rgbBlue = CXIMAGE_GRAY; qGray.rgbGreen = CXIMAGE_GRAY; qGray.rgbRed = CXIMAGE_GRAY; for(long y=rcSel.bottom; y<rcSel.top; y++){ for(long x=rcSel.left; x<rcSel.right; x++){ if (pCxLayer->BlindSelectionIsInside(x,y)){ m_spClipboardLayer->BlindSetPixelColor(x - rcSel.left, y - rcSel.bottom, pCxLayer->BlindGetPixelColor(x,y)); pCxLayer->BlindSetPixelColor(x, y, qGray); pCxLayer->AlphaSet(x, y, 0); } else m_spClipboardLayer->AlphaSet (x - rcSel.left, y - rcSel.bottom, 0); } } return true; }
BOOL CSonicImage::Rotate(int nAngle, POINT * pScout /* = NULL */) { if(m_Dib.IsValid() == FALSE) { return FALSE; } nAngle = abs(nAngle) % 360; int nBitX = nAngle <= 180 ? 1 : 0; int nBitY = nAngle > 90 && nAngle <= 270 ? 1 : 0; int nSrcW = m_nWidth; int nSrcH = m_nHeight; const int nBytePixel = 4; BYTE * pSrc = m_Dib.GetBits(); int nNewX = (nSrcW - nBitX) >> 1; int nNewY = (nSrcH - nBitY) >> 1; double m1 = -nSrcW / 2.0f; double m2 = nSrcW / 2.0f; double n1 = nSrcH / 2.0f; double n2 = -nSrcH / 2.0f; POINT pt1 = {(int)(m1 * COS(nAngle) + n1 * SIN(nAngle)) >> 10, (int)(-m1 * SIN(nAngle) + n1 * COS(nAngle)) >> 10}; POINT pt2 = {(int)(m2 * COS(nAngle) + n1 * SIN(nAngle)) >> 10, (int)(-m2 * SIN(nAngle) + n1 * COS(nAngle)) >> 10}; POINT pt3 = {(int)(m2 * COS(nAngle) + n2 * SIN(nAngle)) >> 10, (int)(-m2 * SIN(nAngle) + n2 * COS(nAngle)) >> 10}; POINT pt4 = {(int)(m1 * COS(nAngle) + n2 * SIN(nAngle)) >> 10, (int)(-m1 * SIN(nAngle) + n2 * COS(nAngle)) >> 10}; int i, j, x1, y1, x11, y11; i = abs(pt3.x - pt1.x); j = abs(pt4.x - pt2.x); int nDestW = max(i, j); i = abs(pt3.y - pt1.y); j = abs(pt4.y - pt2.y); int nDestH = max(i, j); m_nWidth = nDestW; m_nHeight = nDestH; HBITMAP hBmp = NULL; m_Dib.Resize(m_nWidth, m_nHeight, &hBmp); BYTE * pDest = m_Dib.GetBits(); int temp; int nOriginX = nDestW >> 1; int nOriginY = nDestH >> 1; for(i = 0; i < nDestH; i++) { for(j = 0; j < nDestW; j++) { x1 = j - nOriginX; y1 = nOriginY - i; temp = (x1 * COS(nAngle) + y1 * SIN(nAngle)) >> 10; x11 = temp + nNewX; temp = (-x1 * SIN(nAngle) + y1 * COS(nAngle)) >> 10; y11 = nNewY - temp; if(x11 >= 0 && x11 < nSrcW && y11 >= 0 && y11 < nSrcH) { COLORREF color = *(DWORD *)(pSrc + (nSrcW * nBytePixel * y11) + x11 * nBytePixel); *(DWORD *)(pDest + i * nBytePixel * nDestW + j * nBytePixel) = color; } } } if(hBmp) { DeleteObject(hBmp); } if(pScout) { x1 = pScout->x - nNewX; y1 = nNewY - pScout->y; nAngle = 360 - nAngle; x11 = (x1 * COS(nAngle) + y1 * SIN(nAngle)) >> 10; x11 = x11 + nOriginX; y11 = (-x1 * SIN(nAngle) + y1 * COS(nAngle)) >> 10; y11 = nOriginY - y11; pScout->x = x11; pScout->y = y11; } EnableAlphaChannel(FALSE); return TRUE; } BOOL CSonicImage::SaveAsFile(LPCTSTR lpszFileName, enImageType imgType, int nQuality /* = 0 */) { if(m_Dib.IsValid() == FALSE) { return FALSE; } CxImage img; if(img.CreateFromHBITMAP(m_Dib.GetHBitmap()) == FALSE) { return FALSE; } if(IsAlphaChannelValid() && (imgType == IMAGE_TYPE_BMP || imgType == IMAGE_TYPE_PNG || imgType == IMAGE_TYPE_TGA || imgType == IMAGE_TYPE_ICO)) { img.AlphaCreate(); for(int i = 0; i < m_nHeight; i++) { for(int j = 0; j < m_nWidth; j++) { BYTE bAlpha = *(m_Dib.GetBits() + i * m_nWidth * 4 + j * 4 + 3); img.AlphaSet(j, i, bAlpha); } } } DWORD dwType = 0; switch (imgType) { case IMAGE_TYPE_BMP: dwType = CXIMAGE_FORMAT_BMP; break; case IMAGE_TYPE_JPEG: dwType = CXIMAGE_FORMAT_JPG; nQuality = nQuality ? nQuality : DEFAULT_JPEG_QULITY; img.SetJpegQuality(nQuality); break; case IMAGE_TYPE_TGA: dwType = CXIMAGE_FORMAT_TGA; break; case IMAGE_TYPE_PNG: dwType = CXIMAGE_FORMAT_PNG; break; case IMAGE_TYPE_ICO: dwType = CXIMAGE_FORMAT_ICO; break; } CString strPath = lpszFileName; int nFind1 = strPath.ReverseFind(_T('\\')); int nFind2 = strPath.ReverseFind(_T('/')); int nFind = max(nFind1, nFind2); if(nFind != -1) { strPath = strPath.Left(nFind); if(PathFileExists(strPath) == FALSE) { SHCreateDirectoryEx(NULL, strPath, NULL); } } #ifdef _UNICODE USES_CONVERSION; if(img.Save(W2A(lpszFileName), dwType) == FALSE) { return FALSE; } #else if(img.Save(lpszFileName, dwType) == FALSE) { return FALSE; } #endif img.Clear(); return TRUE; } BOOL CSonicImage::Gray() { if(m_Dib.IsValid() == FALSE) { return FALSE; } int nSrcSize = m_nWidth * m_nHeight * 4; CSSE::DoGray(m_Dib.GetBits(), nSrcSize); return TRUE; } HRGN CSonicImage::CreateRgn(DWORD dwColorKey /* = DEFAULT_COLOR_KEY */, int x /* = 0 */, int y /* = 0 */, RECT * pRtSrc /* = NULL */, BOOL bReverse /* = FALSE */) { if(m_Dib.IsValid() == FALSE) { return FALSE; } int nBytePixel = 4; BYTE * pSrc = m_Dib.GetBits(); CRect rtSrc(0, 0, m_nWidth, m_nHeight); if(pRtSrc) { rtSrc = *pRtSrc; } int nLeftx = -1; HRGN hAll = CreateRectRgn(x, y, x + rtSrc.Width(), y + rtSrc.Height()); for(int i = rtSrc.top; i < rtSrc.bottom; i++) { for(int j = rtSrc.left; j < rtSrc.right; j++) { DWORD dwColor = *(DWORD *)(pSrc + (i * m_nWidth * nBytePixel) + j * nBytePixel); if(!bReverse) { if(EQUAL_24COLOR(dwColor, dwColorKey) && nLeftx < 0) { nLeftx = j; } if(nLeftx >= 0 && (!EQUAL_24COLOR(dwColor, dwColorKey) || j + 1 == rtSrc.right)) { if(EQUAL_24COLOR(dwColor, dwColorKey) && j + 1 == rtSrc.right)j++; HRGN hTemp = CreateRectRgn(x + nLeftx - rtSrc.left, y + i - rtSrc.top, x + j - rtSrc.left, y + i + 1 - rtSrc.top); CombineRgn(hAll, hAll, hTemp, RGN_XOR); DeleteObject(hTemp); nLeftx = -1; } } else { if(!EQUAL_24COLOR(dwColor, dwColorKey) && nLeftx < 0) { nLeftx = j; } if(nLeftx >= 0 && (EQUAL_24COLOR(dwColor, dwColorKey) || j + 1 == rtSrc.right)) { if(!EQUAL_24COLOR(dwColor, dwColorKey) && j + 1 == rtSrc.right)j++; HRGN hTemp = CreateRectRgn(x + nLeftx - rtSrc.left, y + i - rtSrc.top, x + j - rtSrc.left, y + i + 1 - rtSrc.top); CombineRgn(hAll, hAll, hTemp, RGN_XOR); DeleteObject(hTemp); nLeftx = -1; } } } } return hAll; } BOOL CSonicImage::IsAlphaChannelValid() { return m_bAlphaChannel; } BOOL CSonicImage::EnableAlphaChannel(BOOL bModifyRgb /* = TRUE */) { if(m_bAlphaChannel) { return FALSE; } if(m_Dib.IsValid() == FALSE) { return FALSE; } m_bAlphaChannel = TRUE; if(bModifyRgb) { int nSrc = m_nWidth * m_nHeight; DWORD * pSrc = (DWORD *)m_Dib.GetBits(); for(int i = 0; i < nSrc; i++) { CSSE::AdjustAlpha(*pSrc); pSrc++; } } return TRUE; } DWORD CSonicImage::GetPixel(int x, int y) { if(m_Dib.IsValid() == FALSE) { return 0; } if(y < 0 || y >= m_nHeight) { return 0; } if(x < 0 || x >= m_nWidth) { return 0; } return *(DWORD *)(m_Dib.GetBits() + (m_nHeight - y - 1) * m_nWidth * 4 + x * 4); } BOOL CSonicImage::SetPixel(int x, int y, DWORD dwColor) { if(m_Dib.IsValid() == FALSE) { return 0; } if(IsAlphaChannelValid()) { CSSE::AdjustAlpha(dwColor); } else { dwColor |= 0xff000000; } if(y < 0 || y >= m_nHeight) { return 0; } if(x < 0 || x >= m_nWidth) { return 0; } *(DWORD *)(m_Dib.GetBits() + (m_nHeight - y - 1) * m_nWidth * 4 + x * 4) = dwColor; return TRUE; } BYTE * CSonicImage::GetBits() { return m_Dib.GetBits(); } BOOL CSonicImage::Init() { double radiant; for(int i = 0; i < 361; i++) { radiant = (i * PAI) / 180; double temp = sin(radiant) * 1024; Trigonometry[i][0] = ROUND(temp); temp = cos(radiant) * 1024; Trigonometry[i][1] = ROUND(temp); } return TRUE; } BOOL CSonicImage::SetBitsToDevice(HDC hdc, int x /* = 0 */, int y /* = 0 */) { return SetDIBitsToDevice(hdc, x, y, m_nWidth, m_nHeight, 0, 0, 0, m_nHeight, m_Dib.GetBits(), m_Dib.GetBitmapInfo(), DIB_RGB_COLORS) != 0; } RECT CSonicImage::CalculateRectByDrawParam(int x, int y, const DRAW_PARAM * pDp, RECT * pSrc /* = NULL */) { CRect rtSrc, rtDest; int cx = m_nWidth; int cy = m_nHeight; if(pDp && (pDp->dwMask & DP_SRC_CLIP)) { rtSrc = pDp->rtSrc; } else { rtSrc.SetRect(0, 0, m_nWidth, m_nHeight); } cx = rtSrc.Width(); cy = rtSrc.Height(); if(pDp) { if(pDp->dwMask & DP_SCALE) { cx = (int)(rtSrc.Width() * pDp->fScaleX); cy = (int)(rtSrc.Height() * pDp->fScaleY); } if(pDp->dwMask & DP_DEST_LIMIT) { cx = pDp->cx; cy = pDp->cy; } if(pDp->dwMask & DP_TILE) { cx = pDp->nTileLength; } if(pDp->dwMask & DP_VER_TILE) { cy = pDp->nTileLength; } } rtDest.SetRect(x, y, x + cx, y + cy); if(pSrc) { *pSrc = rtSrc; } return rtDest; } BOOL CSonicImage::SetColorKey(DWORD dwColor) { if(IsAlphaChannelValid()) { return FALSE; } CSSE::SetColorKey(m_Dib.GetBits(), m_Dib.GetSize(), dwColor); EnableAlphaChannel(FALSE); return TRUE; } BOOL CSonicImage::Load(HDC hdc, int x, int y, int cx, int cy, BOOL bAlphaChannel /* = FALSE */) { Clear(); BITMAP bmp; GetObject((HBITMAP)GetCurrentObject(hdc, OBJ_BITMAP), sizeof(bmp), &bmp); if(bmp.bmType != 0 || bmp.bmPlanes != 1) { return FALSE; } if(bmp.bmBitsPixel != 32) { return FALSE; } if(PrepareMemDC(cx, cy) == FALSE) { return FALSE; } BitBlt(m_Dib.GetSafeHdc(), 0, 0, cx, cy, hdc, x, y, SRCCOPY); if(bAlphaChannel) { EnableAlphaChannel(FALSE); CSSE::DoOr(0xff000000, m_Dib.GetBits(), m_Dib.GetSize()); } return TRUE; } BOOL CSonicImage::Create(int cx, int cy, DWORD dwColor /* = 0 */, BOOL bWithAlpha /* = FALSE */) { if(PrepareMemDC(cx, cy) == FALSE) { return FALSE; } if(bWithAlpha) { CSSE::AdjustAlpha(dwColor); EnableAlphaChannel(FALSE); } if(dwColor) { Flush(dwColor); } return TRUE; } BOOL CSonicImage::Flush(DWORD dwColor) { if(m_Dib.IsValid() == FALSE) { return FALSE; } CSSE::MemSetDWord(m_Dib.GetBits(), dwColor, m_Dib.GetSize()); return TRUE; } BOOL CSonicImage::SetHsl(int h /* = -1 */, int s /* = -1 */, int l /* = -1 */) { if(IsValid() == FALSE) { return FALSE; } CSSE::SetHSL(m_Dib.GetBits(), m_Dib.GetSize(), h, s, l); return TRUE; } BOOL CSonicImage::MirrorX() { if(IsValid() == FALSE) { return FALSE; } CSSE::MirrorX(m_Dib.GetBits(), m_nWidth, m_nHeight); return TRUE; } BOOL CSonicImage::MirrorY() { if(IsValid() == FALSE) { return FALSE; } CSSE::MirrorY(m_Dib.GetBits(), m_nWidth, m_nHeight); return TRUE; } BOOL CSonicImage::Stretch(int cx, int cy) { if(IsValid() == FALSE) { return FALSE; } if(cx == m_nWidth && cy == m_nHeight) { return TRUE; } CSonicImage * pImg = (CSonicImage *)g_UI.CreateImage(); pImg->CloneFrom(this); PrepareMemDC(cx, cy); CSSE::Stretch(pImg->m_Dib.GetBits(), pImg->GetWidth(), pImg->GetHeight(), m_Dib.GetBits(), cx, cy); g_UI.DestroyObject(pImg); return TRUE; } BOOL CSonicImage::Extend(int cx /* = 0 */, int cy /* = 0 */) { if(IsValid() == FALSE) { return FALSE; } cx = (cx == 0 ? m_nWidth : cx); cy = (cy == 0 ? m_nHeight : cy); CSonicImage * pImg = (CSonicImage *)g_UI.CreateImage(); pImg->CloneFrom(this); PrepareMemDC(cx, cy); for(int i = 0; i < cy; i += pImg->GetHeight()) { for(int j = 0; j < cx; j += pImg->GetWidth()) { pImg->SetBitsToDevice(m_Dib.GetSafeHdc(), j, i); } } g_UI.DestroyObject(pImg); return TRUE; } HDC CSonicImage::GetDC() { if(IsValid() == FALSE) { return NULL; } return m_Dib.GetSafeHdc(); } BOOL CSonicImage::DestroyAlphaChannel() { if(IsValid() == FALSE) { return FALSE; } CSSE::DoAnd(0xffffff, (char *)m_Dib.GetBits(), m_Dib.GetSize()); return TRUE; } BOOL CSonicImage::SetAlphaChannel(BYTE bAlpha) { if(IsValid() == FALSE) { return FALSE; } CSSE::DoOr((bAlpha << 24), (char *)m_Dib.GetBits(), m_Dib.GetSize()); EnableAlphaChannel(FALSE); return TRUE; } BOOL CSonicImage::Blur(int nType /* = 0 */) { if(IsValid() == FALSE) { return FALSE; } char * pTemp = new char[m_Dib.GetSize()]; CSSE::MemCopy(pTemp, m_Dib.GetBits(), m_Dib.GetSize()); int i, j; DWORD * pSrc = (DWORD *)m_Dib.GetBits(); DWORD * pDest = (DWORD *)pTemp; for(i = 1; i < m_Dib.GetHeight() - 1; i++) { for(j = 1; j < m_Dib.GetWidth() - 1; j++) { DWORD dw1 = *(pDest + i * m_Dib.GetWidth() + j); DWORD dw2 = *(pDest + i * m_Dib.GetWidth() + j - 1); DWORD dw3 = *(pDest + i * m_Dib.GetWidth() + j + 1); DWORD dw4 = *(pDest + (i - 1) * m_Dib.GetWidth() + j); DWORD dw5 = *(pDest + (i + 1) * m_Dib.GetWidth() + j); DWORD dw6 = *(pDest + (i - 1) * m_Dib.GetWidth() + j - 1); DWORD dw7 = *(pDest + (i - 1) * m_Dib.GetWidth() + j + 1); DWORD dw8 = *(pDest + (i + 1) * m_Dib.GetWidth() + j - 1); DWORD dw9 = *(pDest + (i + 1) * m_Dib.GetWidth() + j + 1); char r, g, b; r = g = b = 0; switch (nType) { case 0: { // gauss blur r = ((GetRValue(dw1) << 2) + ((GetRValue(dw2) + GetRValue(dw3) + GetRValue(dw4) + GetRValue(dw5)) << 1) + GetRValue(dw6) + GetRValue(dw7) + GetRValue(dw8) + GetRValue(dw9)) >> 4; g = ((GetGValue(dw1) << 2) + ((GetGValue(dw2) + GetGValue(dw3) + GetGValue(dw4) + GetGValue(dw5)) << 1) + GetGValue(dw6) + GetGValue(dw7) + GetGValue(dw8) + GetGValue(dw9)) >> 4; b = ((GetBValue(dw1) << 2) + ((GetBValue(dw2) + GetBValue(dw3) + GetBValue(dw4) + GetBValue(dw5)) << 1) + GetBValue(dw6) + GetBValue(dw7) + GetBValue(dw8) + GetBValue(dw9)) >> 4; } break; case 1: { // even blur r = (GetRValue(dw1) + GetRValue(dw2) + GetRValue(dw3) + GetRValue(dw4) + GetRValue(dw5) + GetRValue(dw6) + GetRValue(dw7) + GetRValue(dw8) + GetRValue(dw9)) / 9; g = (GetGValue(dw1) + GetGValue(dw2) + GetGValue(dw3) + GetGValue(dw4) + GetGValue(dw5) + GetGValue(dw6) + GetGValue(dw7) + GetGValue(dw8) + GetGValue(dw9)) / 9; b = (GetBValue(dw1) + GetBValue(dw2) + GetBValue(dw3) + GetBValue(dw4) + GetBValue(dw5) + GetBValue(dw6) + GetBValue(dw7) + GetBValue(dw8) + GetBValue(dw9)) / 9; } break; } *(pSrc + i * m_Dib.GetWidth() + j) = (0xff000000 | RGB(r, g, b)); } } delete []pTemp; return TRUE; }
void CImgClassCBView::LoadThumbNail1(int iCls, bool bCorrect[], int iImgs_per_Cls[]) { CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd(); CImgClassCBView* pView1; CImgClassCBDoc* pDoc1; pView1 = pFrame->m_pTestView; pDoc1 = pView1->GetDocument(); CListCtrl& ListCtrl1=pView1->GetListCtrl(); CImageList* pImgList1 = &pView1->m_ImageListThumb; int i; for(i=0; i<pImgList1->GetImageCount(); i++) pImgList1->Remove(i); ListCtrl1.DeleteAllItems(); pImgList1->SetImageCount(pDoc1->m_vImgNameTest.size()); TCHAR path1[MAX_PATH]; vector<CString>::iterator iter1; ListCtrl1.SetRedraw(FALSE); int nIndex1 = 0; for(iter1=pDoc1->m_vImgNameTest.begin(); iter1!=pDoc1->m_vImgNameTest.end(); iter1++, nIndex1++) { ListCtrl1.InsertItem(nIndex1, *iter1, nIndex1); } ListCtrl1.SetRedraw(TRUE); ListCtrl1.Invalidate(); //Load Error Tag Img: CString szErrTag = "res\\err.png"; CString szCorTag = "res\\cor.png"; TCHAR path[MAX_PATH]={0}; _stprintf(path, _T("%s"),szErrTag.GetBuffer(0)); int nImageTypeErr=pDoc1->GetTypeFromFileName(path); CxImage imageErr(path, nImageTypeErr); _stprintf(path, _T("%s"),szCorTag.GetBuffer(0)); nImageTypeErr=pDoc1->GetTypeFromFileName(path); CxImage imageCor(path, nImageTypeErr); if(imageErr.IsValid()==false || imageErr.IsValid()==false ) { return; } //////////////////// HBRUSH hBrushBorder=::CreateSolidBrush(RGB(192, 192, 192)); HBRUSH hBrushBk=::CreateSolidBrush(RGB(255, 255, 255)); // Border Size RECT rcBorder; rcBorder.left=rcBorder.top=0; rcBorder.right=THUMBNAIL_WIDTH; rcBorder.bottom=THUMBNAIL_HEIGHT; const float fRatio=(float)THUMBNAIL_HEIGHT/THUMBNAIL_WIDTH; int XDest, YDest, nDestWidth, nDestHeight; nIndex1=0; for(iter1 = pDoc1->m_vImgNameTest.begin(); iter1 != pDoc1->m_vImgNameTest.end(); iter1 ++, nIndex1 ++) { // Load Image File _stprintf(path1, _T("%s\\%s"), pDoc1->m_strCurrentDirectory, *iter1); int nImageType=pDoc1->GetTypeFromFileName(path1); if(nImageType==CXIMAGE_FORMAT_UNKNOWN) continue; CxImage image(path1, nImageType); if(image.IsValid()==false) continue; // Calculate Rect to fit to canvas const float fImgRatio=(float)image.GetHeight()/image.GetWidth(); if(fImgRatio > fRatio) { nDestWidth=THUMBNAIL_HEIGHT/fImgRatio; XDest=(THUMBNAIL_WIDTH-nDestWidth)/2; YDest=0; nDestHeight=THUMBNAIL_HEIGHT; } else { XDest=0; nDestWidth=THUMBNAIL_WIDTH; nDestHeight=THUMBNAIL_WIDTH*fImgRatio; YDest=(THUMBNAIL_HEIGHT-nDestHeight)/2; } //HBRUSH hBrushBorder=::CreateSolidBrush(RGB(192, 1, 192)); //HBRUSH hBrushBk=::CreateSolidBrush(RGB(255, 255, 255)); HBRUSH hBrushBkErr=::CreateSolidBrush(RGB(155, 0, 0)); HBRUSH hBrushBkCor=::CreateSolidBrush(RGB(0, 190, 0)); CClientDC cdc(pView1); HDC hDC=::CreateCompatibleDC(cdc.m_hDC); //建立与pView显示设备兼容的位图 HBITMAP bm = CreateCompatibleBitmap(cdc.m_hDC, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT); //HBITMAP bm2 = CreateCompatibleBitmap(cdc.m_hDC, THUMBNAIL_WIDTH_MASK, THUMBNAIL_HEIGHT_MASK); HBITMAP pOldBitmapImage = (HBITMAP)SelectObject(hDC,bm); // Draw Background ::FillRect(hDC, &rcBorder, hBrushBk); //::FillRect(hDC, &rcBorderInside, hBrushBk); // Draw Image image.Stretch(hDC, XDest + 2, YDest + 2, nDestWidth - 4, nDestHeight - 4); // Draw Border //::FrameRect(hDC, &rcBorderInside, hBrushBorder); SelectObject(hDC, pOldBitmapImage); // Attach to Bitmap and Replace image in CImageList CBitmap bitmap; bitmap.Attach(bm); pImgList1->Replace(nIndex1, &bitmap, NULL); // Redraw only a current item for removing flickering and fast speed. ListCtrl1.RedrawItems(nIndex1, nIndex1); /////////////////////////////////////////////////////////////////////////// //对标号不对的图片进行标记(正确的打对号) CxImage *pImg; int iImgNo = iImgs_per_Cls[nIndex1]; if(!bCorrect[iImgNo / 100 * 50 + iImgNo % 50]) pImg = &imageErr; else pImg = &imageCor; HBITMAP bmErr = CreateCompatibleBitmap(cdc.m_hDC, THUMBNAIL_WIDTH_MASK, THUMBNAIL_HEIGHT_MASK); HBITMAP pOldBitmapImageErr = (HBITMAP)SelectObject(hDC,bmErr); ::FillRect(hDC, &rcBorder, hBrushBk); pImg->AlphaSet(100); pImg->Stretch(hDC, 0, 0, THUMBNAIL_WIDTH_MASK, THUMBNAIL_HEIGHT_MASK); SelectObject(hDC, pOldBitmapImage); CBitmap bitmapErr; bitmapErr.Attach(bmErr);//将位图贴到ImageList控件上 pImgList1->Replace(nIndex1, &bitmapErr, NULL); pImgList1->SetOverlayImage(nIndex1,1); CPoint myPoint(XDest,YDest); pImgList1->Draw((CDC*)&hDC, 0, myPoint, INDEXTOOVERLAYMASK(1)); ListCtrl1.RedrawItems(nIndex1, nIndex1); DeleteObject(bmErr); /////////////////////////////////////////////////////////////////////////// // Release used DC and Object DeleteDC(hDC); DeleteObject(bm); DeleteObject(hBrushBkErr); DeleteObject(hBrushBkCor); } DeleteObject(hBrushBorder); DeleteObject(hBrushBk); ListCtrl1.Invalidate(); return; }