BOOL CStaffSetDlg::ShowPhoto(const CString& strPhotoPath, CWnd* pWnd) { POSITION pos=m_ListCtr_Staff.GetFirstSelectedItemPosition(); int index=m_ListCtr_Staff.GetNextSelectedItem(pos); SLZStaff staffinfo=m_List_StaffInfo.GetAt(m_List_StaffInfo.FindIndex(index)); CStatic* picPhoto = (CStatic*)pWnd; CDC* pDC = picPhoto->GetWindowDC(); CRect rect; picPhoto->GetClientRect(&rect); CImage img; if(strPhotoPath.IsEmpty()) { pDC->SelectStockObject(GRAY_BRUSH); pDC->FillRect( &rect, pDC->GetCurrentBrush()); UpdateData(FALSE); return FALSE; } HRESULT hResult = img.Load(strPhotoPath); if(FAILED(hResult)) { MessageBox(_T("图片路径错误,导入失败")); staffinfo.SetStaffPhoto(_T("")); m_ListCtr_Staff.SetItemText(index,4,_T("未配置")); m_List_StaffInfo.GetAt(m_List_StaffInfo.FindIndex(index))=staffinfo; return FALSE; } pDC->SetStretchBltMode(STRETCH_HALFTONE); img.Draw(pDC->m_hDC, 0, 0, rect.Width(), rect.Height(), 0, 0, img.GetWidth(), img.GetHeight()); //把图片填充在控件中 return TRUE; }
static BOOL CImageToMat(const CImage& image, Mat& img) { img.create(image.GetHeight(), image.GetWidth(), CV_8UC3); if (img.data == NULL) return FALSE; // 支持24位、32位图 int bpp = image.GetBPP() / 8; if (bpp < 3) return FALSE; for (int y = 0; y < image.GetHeight(); y++) { BYTE* src = (BYTE*)image.GetPixelAddress(0, y); BYTE* dst = img.ptr<BYTE>(y); for (int x = 0; x < image.GetWidth(); x++) { dst[0] = src[0]; dst[1] = src[1]; dst[2] = src[2]; src += bpp; dst += 3; } } return TRUE; }
BOOL CChildView::OnEraseBkgnd(CDC* pDC) { CRect r; CAutoLock cAutoLock(&m_csLogo); CImage img; img.Attach(m_logo); if (((CMainFrame*)GetParentFrame())->IsSomethingLoaded()) { pDC->ExcludeClipRect(m_vrect); } else if (!img.IsNull()) { GetClientRect(r); int w = min(img.GetWidth(), r.Width()); int h = min(img.GetHeight(), r.Height()); int x = (r.Width() - w) / 2; int y = (r.Height() - h) / 2; r = CRect(CPoint(x, y), CSize(w, h)); int oldmode = pDC->SetStretchBltMode(STRETCH_HALFTONE); img.StretchBlt(*pDC, r, CRect(0, 0, img.GetWidth(), img.GetHeight())); pDC->SetStretchBltMode(oldmode); pDC->ExcludeClipRect(r); } img.Detach(); GetClientRect(r); pDC->FillSolidRect(r, 0); return TRUE; }
/* NotifyRanges() Posiziona l'immagine nella vista. */ void CWallBrowserStretchView::NotifyRanges(BOOL bResetZoom/*=TRUE*/) { CImage *pImage = GetDocument()->GetImage(); if(pImage) { CSize size(0,0); if(bResetZoom) { size.cx = pImage->GetWidth(); size.cy = pImage->GetHeight(); } else { size.cx = (int)((double)pImage->GetWidth() * GetZoomRatio()); size.cy = (int)((double)pImage->GetHeight() * GetZoomRatio()); } SetZoomSizes(size); if(bResetZoom) { SetZoomMode(MODE_ZOOMOFF); SetZoomRatio(1.0); } } }
void ShapeWindowFromBitmap(CImage &image,CWnd *pWnd,COLORREF keyColor) { pWnd->MoveWindow(0,0,image.GetWidth(),image.GetHeight()); if (!image.IsNull()) { CRgn crRgn, crRgnTmp; crRgn.CreateRectRgn(0,0,0,0); for (int nY = 0; nY <= image.GetHeight(); nY++) { int nX = 0; do { while (nX <= image.GetWidth() && image.GetPixel(nX, nY) == keyColor) nX++; int iLeftX = nX; while (nX <= image.GetWidth() && image.GetPixel(nX, nY) != keyColor) ++nX; crRgnTmp.CreateRectRgn(iLeftX, nY, nX, nY+1); crRgn.CombineRgn(&crRgn, &crRgnTmp, RGN_OR); crRgnTmp.DeleteObject(); }while(nX < image.GetWidth()); nX = 0; } pWnd->SetWindowRgn(crRgn,TRUE); crRgn.DeleteObject(); } }
BOOL CChildView::OnEraseBkgnd(CDC* pDC) { CRect r; CImage img; img.Attach(m_img); if ((m_pMainFrame->GetLoadState() != MLS::CLOSED || (!m_bFirstMedia && m_pMainFrame->m_controls.DelayShowNotLoaded())) && !m_pMainFrame->IsD3DFullScreenMode() && !m_pMainFrame->m_fAudioOnly) { pDC->ExcludeClipRect(m_vrect); } else if (!img.IsNull()) { const double dImageAR = double(img.GetWidth()) / img.GetHeight(); GetClientRect(r); int width = r.Width(); int height = r.Height(); if (!m_bCustomImgLoaded) { // Limit logo size // TODO: Use vector logo to preserve quality and remove limit. width = std::min(img.GetWidth(), width); height = std::min(img.GetHeight(), height); } double dImgWidth = height * dImageAR; double dImgHeight; if (width < dImgWidth) { dImgWidth = width; dImgHeight = dImgWidth / dImageAR; } else { dImgHeight = height; } int x = std::lround((r.Width() - dImgWidth) / 2.0); int y = std::lround((r.Height() - dImgHeight) / 2.0); r = CRect(CPoint(x, y), CSize(std::lround(dImgWidth), std::lround(dImgHeight))); if (!r.IsRectEmpty()) { if (m_resizedImg.IsNull() || r.Width() != m_resizedImg.GetWidth() || r.Height() != m_resizedImg.GetHeight() || img.GetBPP() != m_resizedImg.GetBPP()) { m_resizedImg.Destroy(); m_resizedImg.Create(r.Width(), r.Height(), std::max(img.GetBPP(), 24)); HDC hDC = m_resizedImg.GetDC(); SetStretchBltMode(hDC, STRETCH_HALFTONE); img.StretchBlt(hDC, 0, 0, r.Width(), r.Height(), SRCCOPY); m_resizedImg.ReleaseDC(); } m_resizedImg.BitBlt(*pDC, r.TopLeft()); pDC->ExcludeClipRect(r); } } img.Detach(); GetClientRect(r); pDC->FillSolidRect(r, 0); return TRUE; }
// 取图片显示的尺寸 SIZE CImageViewDlg::GetImageSize(const CImage& image) { CRect rect; m_imageStatic.GetWindowRect(rect); if (image.GetWidth() <= rect.Width()) return SIZE{ image.GetWidth(), image.GetHeight() }; else { float scale = (float)rect.Width() / image.GetWidth(); return SIZE{ rect.Width(), (int)(image.GetHeight() * scale) }; } }
// // WriteImage() // write an image to a file in PNG format // This version writes the entire image // void CImageIOPng::WriteImage(const CImage& image, CNcbiOstream& ostr, CImageIO::ECompress compress) { // make sure we've got an image if ( !image.GetData() ) { NCBI_THROW(CImageException, eWriteError, "CImageIOPng::WriteImage(): " "attempt to write an empty image"); } // validate our image - we need RGB or RGBA images if (image.GetDepth() != 3 && image.GetDepth() != 4) { string msg("CImageIOPng::WriteImage(): invalid image depth: "); msg += NStr::NumericToString(image.GetDepth()); NCBI_THROW(CImageException, eWriteError, msg); } png_structp png_ptr = NULL; png_infop info_ptr = NULL; try { // initialize png stuff s_PngWriteInit(png_ptr, info_ptr, image.GetWidth(), image.GetHeight(), image.GetDepth(), compress); // begin writing data png_set_write_fn(png_ptr, &ostr, s_PngWrite, s_PngFlush); png_write_info(png_ptr, info_ptr); // write our image, line-by-line unsigned char* row_ptr = const_cast<unsigned char*> (image.GetData()); size_t width = image.GetWidth(); size_t height = image.GetHeight(); size_t depth = image.GetDepth(); for (size_t i = 0; i < height; ++i) { png_write_row(png_ptr, row_ptr); row_ptr += width * depth; } // standard clean-up png_write_end(png_ptr, info_ptr); s_PngWriteFinalize(png_ptr, info_ptr); } catch (...) { s_PngWriteFinalize(png_ptr, info_ptr); throw; } }
bool CThirdoneDlg::Show_picture(CString imgPath) { int height, width; CRect rect;//定义矩形类 CRect rect1; CImage image; //创建图片类 image.Load(imgPath); height = image.GetHeight(); width = image.GetWidth(); this->GetClientRect(&rect); //获得pictrue控件所在的矩形区域 CDC *pDc = this->GetDC();//获得pictrue控件的Dc SetStretchBltMode(pDc->m_hDC,STRETCH_HALFTONE); xScale=(float)rect.Width()/(float)width; yScale=(float)rect.Height()/(float)height; if(width<=rect.Width() && height<=rect.Width()) //小图片,不缩放 { rect1 = CRect(rect.TopLeft(), CSize(width,height)); image.StretchBlt(pDc->m_hDC,rect,SRCCOPY); //将图片画到Picture控件表示的矩形区域 return TRUE; } else { xScale=(float)rect.Width()/(float)width; yScale=(float)rect.Height()/(float)height; float ScaleIndex=(xScale<=yScale?xScale:yScale); rect1 = CRect(rect.TopLeft(), CSize((int)width*ScaleIndex,(int)height*ScaleIndex)); image.StretchBlt(pDc->m_hDC,rect,SRCCOPY); //将图片画到Picture控件表示的矩形区域 } ReleaseDC(pDc);//释放picture控件的Dc return TRUE; }
/* OnEditCopy() */ void CWallBrowserStretchView::OnEditCopy(void) { CWaitCursor cursor; BOOL bCopied = FALSE; // copia il contenuto dell'immagine nella clipboard if(::OpenClipboard(NULL)) { if(::EmptyClipboard()) { CWallBrowserDoc* pDoc = (CWallBrowserDoc*)GetDocument(); if(pDoc) { CImage *pImage = pDoc->GetImage(); if(pImage && pImage->GetWidth() > 0 && pImage->GetHeight() > 0) bCopied = ::SetClipboardData(CF_DIB,pImage->GetDIB())!=(HANDLE)NULL; } } ::CloseClipboard(); } // imposta il redo con l'ultima operazione effettuata if(bCopied) RedoPush(ID_EDIT_COPY); }
bool copyImgDataToCImage(CImage &srcImage,CImage &dstImage,int margin) { margin = abs(margin); //读取图像宽高 int width = srcImage.GetWidth(); int height = srcImage.GetHeight(); if(margin*2 > width) { return false; } //new width int imgWidth = width-2*margin; if(!dstImage.CreateEx(imgWidth,height, 24, BI_RGB))//创建CImage 对象 { return false; } //设置像素 for(int i = height - 1;i >= 0 ; i--) { for(int j = 0; j < imgWidth;j++) { BYTE *pDst = (BYTE*)dstImage.GetPixelAddress(j, i); BYTE *pSrc = (BYTE*)srcImage.GetPixelAddress(j + margin, i); //读取并设置 rgb值 *pDst++ = *pSrc++; // b分量值 *pDst++ = *pSrc++; //g 分量 *pDst = *pSrc; // r分量 } //new offset } return true; }
void CDevILCodec::CodeToFile(const nstring & filename, const CImage &image) { ILuint imageid; CDevILFormats informat; informat.SetExFormat(image.GetPixelFormat()); // Generate the main image name to use. ilGenImages(1, &imageid); // Bind this image name. ilBindImage(imageid); ilTexImage(image.GetWidth(), image.GetHeight(), image.GetDepth(), informat.GetInternalChannels(), informat.GetFormat(), IL_UNSIGNED_BYTE, image.GetBitsPtr()); ilSaveImage(filename.c_str()); ilDeleteImages(1, &imageid); ILenum Error = 0; if((Error = ilGetError()) != NULL) { nstring str("CDevILCodec::CodeToFile: "); str.append(iluErrorString(Error)); throw NOVA_EXP(str.c_str(), BAD_OPERATION); } }
bool CImageEx::SetGray() { CImage *pImage = &m_ImageClone; if ( pImage == NULL && pImage->IsNull() ) { pImage = this; } int nWidth = pImage->GetWidth(); int nHeight = pImage->GetHeight(); BYTE* pArray = (BYTE*)pImage->GetBits(); int nPitch = pImage->GetPitch(); int nBitCount = pImage->GetBPP() / 8; for (int i = 0; i < nHeight; i++) { for (int j = 0; j < nWidth; j++) { int grayVal = (BYTE)(((*(pArray + nPitch * i + j * nBitCount) * 306) + (*(pArray + nPitch * i + j * nBitCount + 1) * 601) + (*(pArray + nPitch * i + j * nBitCount + 2) * 117) + 512 ) >> 10); // 计算灰度值 *(pArray + nPitch * i + j * nBitCount) = grayVal; // 赋灰度值 *(pArray + nPitch * i + j * nBitCount + 1) = grayVal; *(pArray + nPitch * i + j * nBitCount + 2) = grayVal; } } return true; }
int HTMLImage(EE_Context* pContext, LPRECT lpRect, LPCTSTR lpText) { CFileDialog dlg(FALSE, NULL, NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, _T("Image Files(*.jpg;*.jpeg;*.jpe;*.png;*.gif;*.bmp)\0*.jpg;*.jpeg;*.jpe;*.png;*.gif;*.bmp\0All Files(*.*)\0*.*\0\0")); if( dlg.DoModal(pContext->hMain)==IDOK ) { int w=-1; int h=-1; CImage img; if( img.Load( dlg.m_szFileName )==S_OK ) { w=img.GetWidth(); h=img.GetHeight(); img.Destroy(); } CString strText; if( w!=-1 ) strText.Format(_T("<img src=\"%s\" width=\"%d\" height=\"%d\" border=\"0\" alt=\"$0\">"), dlg.m_szFileName, w, h); else strText.Format(_T("<img src=\"%s\" width=\"\" height=\"\" border=\"0\" alt=\"$0\">"), dlg.m_szFileName); HWND hWnd=(HWND)::SendMessage(pContext->hMain, EEM_GETACTIVETEXT, 0, 0); if( hWnd ) ::SendMessage(hWnd, ECM_INSERTSNIPPET, (WPARAM)(LPCTSTR)strText, strText.GetLength()); } return 0; }
void CMapDetail::initMapDetail( const CString& strPrev, int nNum ) { for( int i=1; i <= nNum; ++i ) { CString strTemp; strTemp.Format( "%s_%d.png", strPrev, i ); CString strPath; strPath.Format( "./Editor/mapStyle/%s_%d.png", strPrev, i ); std::string strFileName = strTemp.GetBuffer(); CImage* pImage = new CImage; pImage->Load( strPath ); ImageInfo ii; ii.pImage = pImage; ii.nWidth = pImage->GetWidth(); ii.nHeight = pImage->GetHeight(); ii.nOffsetX = 0; ii.nOffsetY = 0; m_mapImages[strFileName] = ii; } adjustLayout(); }
void PDFwin::getRectImage_width(int pageNo, int rectNo, int width, CImage& image) { SelectionRectangle& rect=::find(mRects, rectNo); PDFDoc* _pdfDoc=mModel->_pdfDoc ; SplashOutputDev* _outputDev=mModel->_outputDev; int totalWidth=int((double)width/(rect.p2.x-rect.p1.x)+0.5); FlLayout* layout=mLayout->findLayout("Automatic segmentation"); int maxWidth=int((double)width/(1.0/(layout->findSlider("N columns")->value()+1.0))+0.5); totalWidth=MIN(maxWidth, totalWidth); double DPI = mModel->calcDPI_width(totalWidth, pageNo); int totalHeight=mModel->calcHeight_DPI(DPI, pageNo); int left=int(rect.p1.x*(double)totalWidth+0.5); int top=int(rect.p1.y*(double)totalHeight+0.5); int right=int(rect.p2.x*(double)totalWidth+0.5); int bottom=int(rect.p2.y*(double)totalHeight+0.5); _pdfDoc->displayPageSlice(_outputDev, pageNo+1, DPI, DPI, 0, gFalse, gTrue, gFalse, left,top, right-left,bottom-top); SplashBitmap* bmp=_outputDev->takeBitmap(); image.SetData(bmp->getWidth(), bmp->getHeight(), bmp->getDataPtr(), bmp->getRowSize()); //ASSERT(image.GetWidth()==width || totalWidth==maxWidth); ASSERT(image.GetHeight()==bottom-top); delete bmp; }
void PDFwin::getRectImage_height(int pageNo, int rectNo, int height, CImage& image) { SelectionRectangle& rect=::find(mRects, rectNo); int totalHeight=int((double)height/(rect.p2.y-rect.p1.y)+0.5); double DPI=getDPI_height(pageNo, rectNo, height); PDFDoc* _pdfDoc=mModel->_pdfDoc ; SplashOutputDev* _outputDev=mModel->_outputDev; int totalWidth=mModel->calcWidth_DPI(DPI, pageNo); int left=int(rect.p1.x*(double)totalWidth+0.5); int top=int(rect.p1.y*(double)totalHeight+0.5); int bottom=int(rect.p2.y*(double)totalHeight+0.5); int right=int(rect.p2.x*(double)totalWidth+0.5); _pdfDoc->displayPageSlice(_outputDev, pageNo+1, DPI, DPI, 0, gFalse, gTrue, gFalse, left,top, right-left,height); SplashBitmap* bmp=_outputDev->takeBitmap(); image.SetData(bmp->getWidth(), bmp->getHeight(), bmp->getDataPtr(), bmp->getRowSize()); ASSERT(image.GetWidth()==right-left); ASSERT(image.GetHeight()==height); delete bmp; }
LRESULT CAboutDlg::OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) { /* HBITMAP hPicture = LoadBitmap(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDB_LOGO)); BITMAP bm; GetObject(hPicture, sizeof (BITMAP), (LPSTR)&bm); CMemDC memdc((HDC)wParam, NULL); HDC hdcCompatible = CreateCompatibleDC(memdc); HBITMAP hOldBMP = (HBITMAP)SelectObject(hdcCompatible, hPicture); RECT rcClient; GetClientRect(&rcClient); memdc.FillSolidRect(&rcClient, GetSysColor(COLOR_3DFACE)); memdc.TransparentBlt(107-bm.bmWidth/2, 116-bm.bmHeight/2, bm.bmWidth, bm.bmHeight, hdcCompatible, 0, 0, bm.bmWidth, bm.bmHeight, 0xff00ff); SelectObject(hdcCompatible, hOldBMP); DeleteDC(hdcCompatible); DeleteObject(hPicture); /*/ CImage Image; LoadImage(&Image, _Module.GetModuleInstance(), IDB_LOGO); CMemDC memdc((HDC)wParam, NULL); RECT rcClient; GetClientRect(&rcClient); memdc.FillRect(&rcClient, COLOR_3DFACE); Image.AlphaBlend(memdc, 107-Image.GetWidth()/2, 116-Image.GetHeight()/2, Image.GetWidth(), Image.GetHeight(), 0, 0, Image.GetWidth(), Image.GetHeight()); /**/ return 0; }
BOOL CNCaptureView::Initialize() { BOOL bRet = FALSE; if (m_brBackground.m_hBrush) { API_VERIFY(m_brBackground.DeleteObject()); } CWindowDC dcOwner(m_hWnd); CDC dcMemory; dcMemory.CreateCompatibleDC(dcOwner); SilverlightCpp::ZipManager* pZipManager = SilverlightCpp::ZipManager::get_Current(); FTLASSERT(pZipManager); CBitmap bmpBackGround; CImage* pImgBgPattern = pZipManager->LoadCImage(_T("/Assets/Images/Main/CaptureView/bg_pattern.png")); // NS FTLASSERT(pImgBgPattern); if (pImgBgPattern) { bmpBackGround.CreateCompatibleBitmap(dcOwner, pImgBgPattern->GetWidth(), pImgBgPattern->GetHeight()); CBitmapHandle holdBitmap = dcMemory.SelectBitmap(bmpBackGround); API_VERIFY(pImgBgPattern->BitBlt(dcMemory, 0, 0, SRCCOPY)); m_brBackground.CreatePatternBrush(bmpBackGround); dcMemory.SelectBitmap(holdBitmap); } //else //{ // bmpBackGround.CreateCompatibleBitmap(dcOwner, 10, 10); // dcMemory.FillSolidRect(0, 0, 5, 5, IMAGE_BACKGROUND_LTGRAY_COLOR); // dcMemory.FillSolidRect(0, 5, 5, 5, IMAGE_BACKGROUND_GRAY_COLOR); // dcMemory.FillSolidRect(5, 0, 5, 5, IMAGE_BACKGROUND_GRAY_COLOR); // dcMemory.FillSolidRect(5, 5, 5, 5, IMAGE_BACKGROUND_LTGRAY_COLOR); //} //CImage* pDefaultImage = pZipManager->LoadCImage(_T("/Assets/Images/Main/CaptureView/bg_default_img.png")); // NS //FTLASSERT(pDefaultImage); //if (pDefaultImage) //{ // m_pDefaultImage = new NDGraphics::CGDIPImage; // m_pDefaultImage->Load(pDefaultImage, ImageFormatPNG); // //API_VERIFY(m_canvasDefaultImage.Create(NULL, m_pDefaultImage->GetWidth(), m_pDefaultImage->GetHeight(), 32)); //} m_strMousePosInfo = CStringResouceMgr::Instance()->GetStringData(TEXT("NCAPTURE_IMAGE_INFO")).c_str(); m_strMouseSelectInfo = CStringResouceMgr::Instance()->GetStringData(TEXT("NCAPTURE_IMAGE_SELECT_INFO")).c_str(); _EventHook(); //API_VERIFY( NULL != m_brBackGround.CreateHatchBrush(HS_CROSS, RGB(127,127,127))); m_bInited = TRUE; //CRect rcClient; //GetClientRect(rcClient); //InvalidateRect(rcClient, TRUE); //_CalcImageSize(); return bRet; }
static PointF GetRotPos( CImage &alpha, const PointF &pos ) { PointF ret = { pos.X + alpha.GetWidth() / 2, pos.Y + alpha.GetHeight() / 2 }; return ret; }
static PointF GetAlphaImgBlendPos( CImage &dest, CImage &alpha ) { PointF pos; if( dest.GetWidth() <= alpha.GetWidth() || dest.GetHeight() <= alpha.GetHeight() ) { PutoutLog( LOG_FILE, LT_WARNING, "Alpha image's size is invalid.[%u,%u].", alpha.GetWidth(), alpha.GetHeight() ); pos.X = pos.Y = 0; } else { pos.X = random( dest.GetWidth() - alpha.GetWidth() + 1 ); pos.Y = random( dest.GetHeight() - alpha.GetHeight() + 1 ); } return pos; }
static void BlendSelSign( CImage &back, const RectF &render_rect, int sel ) { CFileListManager &file_manager = GetInst( CFileListManager ); CImage img; CreateImgFromBuffer( file_manager.GetSelSign( sel ), img ); PointF render_pos = GetRandPosInULRect( img.GetWidth(), img.GetHeight(), render_rect ); back.AlphaBlend( &img, render_pos.X, render_pos.Y, 1.0f ); }
void Csmoothorsharp::FilterImg(int* temp,CImage imga){ int nW=imga.GetWidth()-1; int nH=imga.GetHeight()-1; byte *pRealData; pRealData=(byte*)imga.GetBits(); int pit=imga.GetPitch(); int bitCount=imga.GetBPP()/8; for (int i=1;i<nH;i++) { for (int j=1;j<nW;j++) { int Rval=0,Gval=0,Bval=0,indx=0; for ( int row=-1;row<=1;row++) { for (int col=-1;col<=1;col++) { Bval+=((int)(int)(*(pRealData+pit*(i+row)+(j+col)*bitCount))) *temp[indx]; Gval=((int)(int)(*(pRealData+pit*(i+row)+(j+col)*bitCount+1)))*temp[indx]; Rval=((int)(int)(*(pRealData+pit*(i+row)+(j+col)*bitCount+2)))*temp[indx]; indx++; } } //template work is over,You need get the center point pixel. Rval=(int)(Rval*cval); if (Rval>255) Rval=255; else if(Rval<0) Rval=0; Gval=(int)(Gval*cval); if (Gval>255) Gval=255; else if(Gval<0) Gval=0; Bval=(int)(Bval*cval); if (Bval>255) Bval=255; else if (Bval<0) Bval=0; //ok,write the new pixel into the pic. *(pRealData+pit*(i-1)+(j-1)*bitCount)=Bval; *(pRealData+pit*(i-1)+(j-1)*bitCount+1)=Gval; *(pRealData+pit*(i-1)+(j-1)*bitCount+2)=Rval; } } //CALL the OnDraw in MFC }
/* UndoPop() */ BOOL CWallBrowserStretchView::UndoPop(void) { BOOL bUndo = FALSE; if(--m_nUndoLevel >= 0) { CWallBrowserDoc* pDoc = (CWallBrowserDoc*)GetDocument(); if(pDoc) { CImage *pImage = pDoc->GetImage(); if(pImage && pImage->GetWidth() > 0 && pImage->GetHeight() > 0) { int index; CImage* pImg; UNDOINFO* undoinfo = m_UndoInfo.Pop(index); if(index >= 0 && undoinfo) { m_nRedo = undoinfo->nRedo; CImageFactory* pImgFactory = undoinfo->pImageFactory; pImg = pImgFactory->GetImage(); HDIB hDib = pImg->GetDIB(&(undoinfo->DibInfo)); if(hDib) { pImage->SetDIB(hDib,&(undoinfo->DibInfo)); ::GlobalFree(hDib); delete (CImageFactory*)undoinfo->pImageFactory; delete undoinfo; bUndo = TRUE; } else { delete (CImageFactory*)undoinfo->pImageFactory; delete undoinfo; } } else ::MessageBeep(MB_ICONEXCLAMATION); } } } else m_nUndoLevel++; CWnd* pWnd = AfxGetMainWnd(); if(pWnd) { pWnd->SendMessage(WM_EDIT_UNDO,UndoEnabled(),0L); pWnd->SendMessage(WM_EDIT_REDO,RedoEnabled(),0L); } return(bUndo); }
/* UndoPush() */ BOOL CWallBrowserStretchView::UndoPush(int nID) { BOOL bUndo = FALSE; if(++m_nUndoLevel <= MAX_STACK_SIZE) { // salva il contenuto dell'immagine nello stack per l'undo CWallBrowserDoc* pDoc = (CWallBrowserDoc*)GetDocument(); if(pDoc) { CImage *pImage = pDoc->GetImage(); if(pImage && pImage->GetWidth() > 0 && pImage->GetHeight() > 0) { CImage* pImg; CImageFactory* pImgFactory = new CImageFactory(); char szLibraryName[_MAX_PATH+1]; strcpy(szLibraryName,pImage->GetLibraryName()); pImg = pImgFactory->Create(szLibraryName,sizeof(szLibraryName)); DIBINFO DibInfo; DibInfo.nPerspective = 0; HDIB hDib = pImage->GetDIB(&DibInfo); if(hDib) { pImg->SetDIB(hDib,&DibInfo); ::GlobalFree(hDib); UNDOINFO* undoinfo = new UNDOINFO; undoinfo->pImageFactory = pImgFactory; undoinfo->DibInfo.nPerspective = DibInfo.nPerspective; undoinfo->nRedo = nID; int nLevel = m_UndoInfo.Push(undoinfo); if(nLevel!=-1) bUndo = TRUE; } else { delete pImgFactory; } } } } else m_nUndoLevel--; CWnd* pWnd = AfxGetMainWnd(); if(pWnd) { pWnd->SendMessage(WM_EDIT_UNDO,UndoEnabled(),0L); pWnd->SendMessage(WM_EDIT_REDO,FALSE,0L); } return(bUndo); }
void CPolySelection::OnMouseMove( DragState dragState, CPoint point, CImage* pImage, CImage* pImage2 ) { CImage* image = dragState == CSelection::DRAGGING ? pImage : pImage2; if( dragState == CSelection::DRAGGING ) { point.x = max( 1, point.x ); point.y = max( 1, point.y ); point.x = min( image->GetWidth() - 1, point.x ); point.y = min( image->GetHeight() - 1, point.y ); m_nextPoint = point; } if( dragState == CSelection::FIXED ) { point.x -= pImage->GetWidth(); point.x = max( 1, point.x ); point.y = max( 1, point.y ); point.x = min( image->GetWidth() - GetBoundingBox().Width() - 1, point.x ); point.y = min( image->GetHeight() - GetBoundingBox().Height() - 1, point.y ); if( m_verts.size() <= 0 ) { return; } auto diff = point - GetBasePoint(); std::vector<CPoint> newVerts; for( int i=0; i<(int)m_verts.size(); i++ ) { auto p = m_verts[i]; newVerts.push_back( p + diff ); } m_verts = newVerts; } }
/* OnEditPaste() */ void CWallBrowserStretchView::OnEditPaste(void) { CWaitCursor cursor; BOOL bPasted = FALSE; // salva il contenuto corrente per l'undo if(!UndoPush(ID_EDIT_PASTE)) if(::MessageBoxResource(this->m_hWnd,MB_ICONWARNING|MB_YESNO,WALLBROWSER_PROGRAM_NAME,IDS_ERROR_UNDOSTACKFULL)==IDNO) return; // incolla il contenuto della clipboard nell'immagine if(::OpenClipboard(NULL)) { HDIB hDib = (HDIB)::GetClipboardData(CF_DIB); ::CloseClipboard(); if(hDib) { CWallBrowserDoc* pDoc = (CWallBrowserDoc*)GetDocument(); if(pDoc) { CImage *pImage = pDoc->GetImage(); if(pImage && pImage->GetWidth() > 0 && pImage->GetHeight() > 0) if(pImage->SetDIB(hDib)) { m_bHavePicture = TRUE; pDoc->SetModifiedFlag(TRUE); CWnd* pWnd = AfxGetMainWnd(); if(pWnd) { pWnd->SendMessage(WM_FILE_SAVE_AS,TRUE,0L); pWnd->SendMessage(WM_FILE_SAVE,TRUE,0L); pWnd->SendMessage(WM_FILE_MOVE,TRUE,0L); pWnd->SendMessage(WM_FILE_DELETE,TRUE,0L); } Invalidate(TRUE); bPasted = TRUE; } } } } // se l'incolla non riesce ripristina il contenuto originale if(!bPasted) { UndoPop(); Invalidate(TRUE); } // imposta il redo con l'ultima operazione effettuata if(bPasted) RedoPush(ID_EDIT_PASTE); }
MulRect CPicDlgQuery::GetWidthHeight(const string& path) { CImage img; HRESULT hr = img.Load(CCharset::AnsiToUnicode(path).c_str()); if (hr == S_OK) { MulRect rect = { 0, 0, img.GetWidth(), img.GetHeight() }; img.Destroy(); return rect; } return MulRect(); }
void CInsertDlg::drawpic() { CRect rectPic; m_pic.GetClientRect(&rectPic); //m_picture为Picture Control控件变量,获得控件的区域对象 CDC* pDC = m_pic.GetWindowDC(); //获得显示控件的DC CImage *pImage = new CImage(); //装载图像的类 int n = all; if (cur< n){ //还有图片可以显示 HRESULT ret; CString path = CString(setting.libpath.c_str()) + CString("\\") + CString(album.record(fileno[cur]).filename().c_str()); ret = pImage->Load(path);//从磁盘装载图片,根据页面计算得到的图片下标 if (FAILED(ret)){ MessageBox(path + _T("不存在!")); return; } int width = rectPic.Width(); //显示区域的宽和高 int height = rectPic.Height(); int picW = pImage->GetWidth(); //图片的宽和高 int picH = pImage->GetHeight(); //计算缩放比 double r1 = double(picW) / double(width); double r2 = double(picH) / double(height); //r为最优缩放比例 double r = (r1 >= r2 ? r1 : r2); int w = picW / r; int h = picH / r; int sw = (width - w) / 2; int sh = (height - h) / 2; //防止缩放后失真 SetStretchBltMode(pDC->m_hDC, HALFTONE); //SetBrushOrgEx(pDC->m_hDC, 0, 0, NULL); pImage->StretchBlt(pDC->m_hDC, sw, sh, w, h); //显示图片 pImage->Draw(pDC->m_hDC, sw, sh, w, h); ReleaseDC(pDC); delete pImage; } else{ m_pic.ShowWindow(SW_HIDE); } }
FTL::FileFindResultHandle CLotteryMgr::OnFindFile(LPCTSTR pszFilePath, const WIN32_FIND_DATA& findData, LPVOID pParam) { HRESULT hr = E_FAIL; BOOL bRet = FALSE; Gdiplus::Status sts = Gdiplus::Ok; if (ftwtContinue != m_threadInit.GetThreadWaitType(INFINITE)) { return rhStop; } if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY) { //find result file FTLTRACE(TEXT("OnFindFile: %s\n"), pszFilePath); CImage img; COM_VERIFY(img.Load(pszFilePath)); if (SUCCEEDED(hr)) { LotteryInfoPtr pLotteryInfo(new LotteryInfo(pszFilePath, FALSE)); CRect rcThumbnail(0, 0, m_szThumbnail.cx, m_szThumbnail.cy); CSize szImage(img.GetWidth(), img.GetHeight()); CRect rcDrawTarget = m_pCalcRect->GetFitRect(rcThumbnail, szImage); if (rcDrawTarget.bottom <= rcDrawTarget.top) { rcDrawTarget.bottom = rcDrawTarget.top + 1; } if (rcDrawTarget.right <= rcDrawTarget.left) { rcDrawTarget.right = rcDrawTarget.left + 1; } API_VERIFY(pLotteryInfo->imgThumbnail.Create(rcDrawTarget.Width(), rcDrawTarget.Height(), 32, CImage::createAlphaChannel)); if (bRet) { CImageDC dc(pLotteryInfo->imgThumbnail); Gdiplus::Bitmap bmp((HBITMAP)img, NULL); Gdiplus::Graphics graphic(dc); GDIPLUS_VERIFY(graphic.DrawImage(&bmp, 0, 0, rcDrawTarget.Width(), rcDrawTarget.Height())); SendMessage(m_hWndControl, UM_ADD_LOTTERY_INFO, (WPARAM)pLotteryInfo.get(), NULL); m_allLotteryInfos.push_back(pLotteryInfo); } } } return rhContinue; }