BOOL SaveFile(DWORD nInx, CString& sPath) { if (imgShow.IsNull()) return FALSE; if (sPath.Empty()) return FALSE; // 获取解码器 CGC gc; ICoderObject* coder = CImgAnalyzer::GetCoder(nInx, &gc); if (!coder) return FALSE; // 编码文件 CIOFile file(sPath, CIOFile::modeCreate | CIOFile::modeReadWrite | CIOFile::shareExclusive); coder->SetFile(&file); coder->Encode(imgShow); return TRUE; }
void TestImageDividerGenerateFromBorder(void) { CImageDivider cImageDivider; CImage cImage; CImage cMask; CImageCelMask* pcRectangle; ReadImage(&cImage, "Input\\splitter.png"); cImageDivider.Init(&cImage); cImageDivider.GenerateFromBorder(&cMask); AssertInt(20, cImageDivider.GetDestImageCels()->NumElements()); pcRectangle = (CImageCelMask*)cImageDivider.GetDestImageCels()->Get(0); AssertInt(1, pcRectangle->GetSubImage()->mcImageRect.miLeft); AssertInt(1, pcRectangle->GetSubImage()->mcImageRect.miTop); AssertInt(13, pcRectangle->GetSubImage()->mcImageRect.GetWidth()); AssertInt(13, pcRectangle->GetSubImage()->mcImageRect.GetHeight()); pcRectangle = (CImageCelMask*)cImageDivider.GetDestImageCels()->Get(1); AssertInt(15, pcRectangle->GetSubImage()->mcImageRect.miLeft); AssertInt(1, pcRectangle->GetSubImage()->mcImageRect.miTop); AssertInt(13, pcRectangle->GetSubImage()->mcImageRect.GetWidth()); AssertInt(13, pcRectangle->GetSubImage()->mcImageRect.GetHeight()); pcRectangle = (CImageCelMask*)cImageDivider.GetDestImageCels()->Get(17); AssertInt(21, pcRectangle->GetSubImage()->mcImageRect.miLeft); AssertInt(39, pcRectangle->GetSubImage()->mcImageRect.miTop); AssertInt(3, pcRectangle->GetSubImage()->mcImageRect.GetWidth()); AssertInt(3, pcRectangle->GetSubImage()->mcImageRect.GetHeight()); WriteImage(&cMask, "Output\\splitter.raw"); AssertFileMemory("input\\splitter.raw", cMask.mcChannels.GetData(), cMask.GetByteSize()); cImageDivider.Kill(); cMask.Kill(); cImage.Kill(); }
void chc_export_image_collection(FILE *fd, CTexture *tex) { CHCTexItem cube_item; CImage *img; memset(&cube_item, 0, sizeof(cube_item)); if (tex->isCubeMap()) { cube_item.type = EColourType_CubeMap; cube_item.checksum = tex->getChecksum(); printf("Item checksum: %08X\n", cube_item.checksum); fwrite(&cube_item, sizeof(cube_item), 1, fd); for (int i = 0; i < ECUBEMAPTYPE_COUNT; i++) { memset(&cube_item, 0, sizeof(cube_item)); img = tex->getImage(i); img->compress(); img->getDimensions(cube_item.width, cube_item.height); cube_item.data_size = img->getDataSize(); cube_item.type = img->getColourType(); cube_item.checksum = 0; fwrite(&cube_item, sizeof(cube_item), 1, fd); fwrite(img->getRawData(), cube_item.data_size, 1, fd); } } else { //write the raw img img = tex->getImage(); //img->compress(); cube_item.type = img->getColourType(); cube_item.data_size = img->getDataSize(); cube_item.checksum = tex->getChecksum(); img->getDimensions(cube_item.width, cube_item.height); uint32_t guess_size = CImage::guessDataSize((EColourType)cube_item.type, cube_item.width, cube_item.height); if (guess_size > cube_item.data_size) { cube_item.data_size = guess_size; } fwrite(&cube_item, sizeof(cube_item), 1, fd); void *addr = img->getRawData(); fwrite(addr, cube_item.data_size, 1, fd); } }
/*! @brief イメージの取得 @param [in] pSelectItem 選択データ @param [out] bitmap イメージ */ BOOL CImageFontDlg::GetBitmapImage(LPVOID pSelectItem, CImage &bitmap) { CRect rect; GetClientRect(&rect); bitmap.Create(rect.Width(), rect.Height(), 32); HDC hDC = bitmap.GetDC(); Gdiplus::Graphics graphics(hDC); graphics.Clear((Gdiplus::ARGB)Gdiplus::Color::White); CString strMessage; strMessage = _T("1234567890\n"); strMessage += _T("abcdefghijklmnopqrstuvwxyz\n"); strMessage += _T("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"); strMessage += _T("あいおえおかきくけこさしすせそたちつてとなにぬねの\n"); strMessage += _T("はひふへほまみむめもやゆよらりるれろわをん\n"); LOGFONT *pLogfont = (LOGFONT *) pSelectItem; Gdiplus::Font font(hDC, pLogfont); Gdiplus::RectF drawLayout(0, 0, (Gdiplus::REAL)rect.Width(), (Gdiplus::REAL)rect.Height()); Gdiplus::StringFormat stringFormat; stringFormat.SetAlignment(Gdiplus::StringAlignmentCenter); stringFormat.SetLineAlignment(Gdiplus::StringAlignmentCenter); stringFormat.SetTrimming(Gdiplus::StringTrimmingNone); Gdiplus::SolidBrush brush((Gdiplus::ARGB)Gdiplus::Color::Black); graphics.SetTextRenderingHint((Gdiplus::TextRenderingHint) (GetSpaceKeyDownCount() % (int)Gdiplus::TextRenderingHintClearTypeGridFit)); graphics.DrawString(strMessage, -1, &font, drawLayout, &stringFormat,&brush); bitmap.ReleaseDC(); return TRUE; }
// // Copies the content of a byte buffer to a MFC image with respect to the image's alignment // // Parameters: // [in] pInbuffer The byte buffer as received from the cam // [in] ePixelFormat The pixel format of the frame // [out] OutImage The filled MFC image // void CAsynchronousGrabDlg::CopyToImage( VmbUchar_t *pInBuffer, VmbPixelFormat_t ePixelFormat, CImage &OutImage ) { const int nHeight = m_ApiController.GetHeight(); const int nWidth = m_ApiController.GetWidth(); const int nStride = OutImage.GetPitch(); const int nBitsPerPixel = OutImage.GetBPP(); VmbError_t Result; if( ( nWidth*nBitsPerPixel ) /8 != nStride ) { Log( _TEXT( "Vimba only supports stride that is equal to width." ), VmbErrorWrongType ); return; } VmbImage SourceImage,DestinationImage; SourceImage.Size = sizeof( SourceImage ); DestinationImage.Size = sizeof( DestinationImage ); SourceImage.Data = pInBuffer; DestinationImage.Data = OutImage.GetBits(); Result = VmbSetImageInfoFromPixelFormat( ePixelFormat, nWidth, nHeight, &SourceImage ); if( VmbErrorSuccess != Result ) { Log( _TEXT( "Error setting source image info." ), static_cast<VmbErrorType>( Result ) ); return; } static const std::string DisplayFormat( "BGR24" ); Result = VmbSetImageInfoFromString( DisplayFormat.c_str(),DisplayFormat.size(), nWidth,nHeight, &DestinationImage ); if( VmbErrorSuccess != Result ) { Log( _TEXT( "Error setting destination image info." ),static_cast<VmbErrorType>( Result ) ); return; } Result = VmbImageTransform( &SourceImage, &DestinationImage,NULL,0 ); if( VmbErrorSuccess != Result ) { Log( _TEXT( "Error transforming image." ), static_cast<VmbErrorType>( Result ) ); } }
void CChildView::OnFileOpen() { CImage image; CString strFilter; CString strAllFilePrompt; CSimpleArray<GUID> aguidFileTypes; HRESULT hResult; INT_PTR nResult; if (m_pSurface == NULL) return; VERIFY(strAllFilePrompt.LoadString(IDS_ALL_IMAGES)); hResult = image.GetImporterFilterString(strFilter, aguidFileTypes, strAllFilePrompt); if(FAILED(hResult)) { CString fmt; fmt.Format(IDS_ERROR_GETEXPORTERFILTER, hResult, _com_error(hResult).ErrorMessage()); ::AfxMessageBox(fmt); return; } CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST, strFilter); dlg.m_ofn.nFilterIndex = m_nFilterLoad; nResult = dlg.DoModal(); if(nResult != IDOK) { return; } m_nFilterLoad = dlg.m_ofn.nFilterIndex; hResult = image.Load(dlg.GetFileName()); ASSERT(SUCCEEDED(hResult)); if (SUCCEEDED(hResult)) { m_pSurface->Import(image); // Stop the weird effects m_bPauseBlur = true; m_bPauseSwarm = true; } }
void Draw_SeedCandidates (std::vector<CPoint> & seed_candidates) { string output_path = gConfig.GetOutputPath(); string image_name = gConfig.GetImageName(); string file_name; CImage* XY = NULL; CPoint* pPoint = NULL; //int giMARGIN2 = 3; XY = new CImage(*CanvasXY); XY->RemovePixels(5); int min_X, max_X, min_Y, max_Y; for (std::vector<CPoint>::iterator i = seed_candidates.begin (); i != seed_candidates.end (); i++) { pPoint = &*i; if (!The3DImage->WithinImagePadding(*pPoint,0)) continue; XY->MarkCrosshairXY(pPoint,2); int radius = Round( static_cast<double>(i->m_fHWidth) / 2.0 ); if(i->m_iHDir != 0) { min_X = max(0,i->m_iX - radius); max_X = min(i->m_iX + radius, XY->m_iCols); pPoint->m_iY = i->m_iY; for (int x = min_X; x <= max_X; x++) { pPoint->m_iX = x; XY->MarkPoint(pPoint, 3); } } else { min_Y = max(0,i->m_iY - radius); max_Y = min(i->m_iY + radius, XY->m_iRows); pPoint->m_iX = i->m_iX; for (int y = min_Y; y <= max_Y; y++) { pPoint->m_iY = y; if(XY->ValidPoint(*pPoint)) XY->MarkPoint(pPoint, 3); } } } file_name = output_path + image_name + "UnverifiedSeeds.tif"; XY->WriteTIFF(file_name); delete XY; XY = NULL; }
// ------------------------------------------------------ // Test_FFMPEG_CaptureCamera // ------------------------------------------------------ void Test_FFMPEG_CaptureCamera(const std::string &video_url) { CFFMPEG_InputStream in_video; if (!in_video.openURL(video_url,false /*grayscale*/, true /* verbose */ )) return; CDisplayWindow win("Video"); CTicTac tictac; tictac.Tic(); unsigned int nFrames = 0; CImage img; while (win.isOpen() && in_video.retrieveFrame(img)) { double fps = ++nFrames / tictac.Tac(); img.textOut(5,5,mrpt::format("%.02f fps",fps),TColor(0x80,0x80,0x80) ); if (nFrames>100) { tictac.Tic(); nFrames=0; } if (nFrames==1) cout << "Video FPS: " << in_video.getVideoFPS() << endl; win.showImage(img); mrpt::system::sleep(10); if (win.keyHit() && win.waitForKey()==27) break; } in_video.close(); mrpt::system::pause(); }
/*--------------------------------------------------------------- assign Image and Z ---------------------------------------------------------------*/ void CMeshFast::assignImageAndZ( const CImage& img, const mrpt::math::CMatrixTemplateNumeric<float> &in_Z) { MRPT_START ASSERT_((img.getWidth() == static_cast<size_t>(in_Z.cols()))&&(img.getHeight() == static_cast<size_t>(in_Z.rows()))) Z = in_Z; // Make a copy: m_textureImage = img; //Update flags/states m_modified_Image = true; m_enableTransparency = false; m_colorFromZ = false; m_isImage = true; pointsUpToDate = false; CRenderizableDisplayList::notifyChange(); MRPT_END }
void CImageExplorer::mousePressEvent(QMouseEvent *event) { iActiveImage = NULL; QListIterator<CImage*> images(iImages); images.toBack (); while (images.hasPrevious()) { CImage* obj = images.previous(); if(obj->IsPointOnObject(event->x(),event->y())) { //iActiveImage = obj; //iImages.move(iImages.indexOf(obj),iImages.count()-1); obj->mousePressEvent(event); SelectImage(obj); CWidget::GetInstance()->paint(); break; } } if(CInfoPanel::GetInstance()) { CInfoPanel::GetInstance()->SetImageExplorerInfoView(); } }
double benchmark_detectFeatures_FASTER(int N, int threshold) { CTicTac tictac; // Generate a random image CImage img; getTestImage(0, img); CFeatureExtraction fExt; CFeatureList feats; fExt.options.featsType = TYP; fExt.options.FASTOptions.threshold = threshold; fExt.options.patchSize = 0; img = img.grayscale(); tictac.Tic(); for (int i = 0; i < N; i++) fExt.detectFeatures(img, feats, 0, MAX_N_FEATS); const double T = tictac.Tac() / N; return T; }
void WriteFile(CImage& img, const char* filename) { // Determine the file extension char *dot = strrchr((char *) filename, '.'); if (strcmp(dot, ".tga") == 0 || strcmp(dot, ".tga") == 0) { if (img.PixType() == typeid(uchar)) WriteFileTGA(*(CByteImage *) &img, filename); else throw CError("ReadFile(%s): haven't implemented conversions yet", filename); } else throw CError("WriteFile(%s): file type not supported", filename); }
/*------------------------------------------------- CAPTURE PICTURE -----------------------------------------------*/ bool CRovio::captureImageAsync( CImage & picture, bool rectified) { try { vector_byte resp; string errormsg; string MF=format("http://%s/Jpeg/CamImg[0000].jpg",options.IP.c_str()); http_get (MF, resp, errormsg, 80, options.user, options.password); CMemoryStream stream( &resp[0], resp.size() ); picture.loadFromStreamAsJPEG(stream); if( rectified )//Comprobar que las matrices existen y son correctas******************** picture.rectifyImageInPlace(options.cameraParams); //picture.saveToFile("0000.jpg"); //cout<<"Response:\n"<<response<<endl; return true; } catch(std::exception &e) { cerr << e.what() << endl; return false; } }
// ------------------------------------------------------ // TestImagesFaceDetection // ------------------------------------------------------ void TestImagesFaceDetection(int argc, char *argv[]) { CImage img; CDisplayWindow win("Result"); mrpt::utils::CTicTac tictac; // For each aditional argument, tty to load an image and detect faces for ( int i = 1; i < argc; i++ ) { string fileName( argv[i] ); if (!img.loadFromFile(myDataDir+fileName)) { cerr << "Cannot load " << myDataDir+fileName << endl; continue; } vector_detectable_object detected; tictac.Tic(); faceDetector.detectObjects( &img, detected ); cout << "Detection time: " << tictac.Tac() << " s" << endl; for ( unsigned int i = 0; i < detected.size() ; i++ ) { ASSERT_( IS_CLASS(detected[i],CDetectable2D ) ) CDetectable2DPtr obj = CDetectable2DPtr( detected[i] ); img.rectangle( obj->m_x, obj->m_y, obj->m_x+obj->m_width, obj->m_y + obj->m_height, TColor(255,0,0) ); } win.showImage(img); mrpt::system::pause(); } }
void WriteFileJPEG(CImage& img, const char* filename, unsigned quality) { JPEGWriter writer; CShape shape = img.Shape(); if(shape.nBands != 1 && shape.nBands != 3) { throw CError("Can only write jpeg files with 1 or 3 channels, %d were given", shape.nBands); } writer.header(shape.width, shape.height, shape.nBands, (shape.nBands == 1)?JPEG::COLOR_GRAYSCALE : JPEG::COLOR_RGB); writer.setQuality(quality); // Reverse color channel order CByteImage imgAux(shape); for(int y = 0; y < shape.height; y++) { uchar* auxIt = (uchar*)imgAux.PixelAddress(0, y, 0); uchar* imgIt = (uchar*)img.PixelAddress(0, y, 0); for(int x = 0; x < shape.width; x++, auxIt += shape.nBands, imgIt += shape.nBands) { for(int c = 0; c < shape.nBands; c++) { auxIt[c] = imgIt[shape.nBands - c - 1]; } } } // Pack row pointers std::vector<uchar*> rowPointers(shape.height); for(int y = 0; y < shape.height; y++) { rowPointers[shape.height - y - 1] = (uchar*) imgAux.PixelAddress(0,y,0); } writer.write(filename, rowPointers.begin()); if (!writer.warnings().empty()) std::cout << writer.warnings() << std::endl; }
void CTopographyRasterizer::RasterizeImage() { CStopWatch sw; sw.Start(); int LowPixel = 255; int HighPixel = 0; byte * ImageData = new byte[ImageSize * ImageSize * 3]; for (int i = 0; i < ImageSize; ++ i) { for (int j = 0; j < ImageSize; ++ j) { int const Index = ImageSize * i + j; double const Value = Buckets[Index].Value; double const Intensity = 1.0f; int const Pixel = Clamp<int>((int) (Value * Intensity), 0, 255); LowPixel = Min(LowPixel, Pixel); HighPixel = Max(HighPixel, Pixel); ImageData[Index * 3 + 0] = Pixel; ImageData[Index * 3 + 1] = Pixel; ImageData[Index * 3 + 2] = Pixel; } } Log::Info("Low value: %d High Value: %d", LowPixel, HighPixel); CImage * Image = new CImage(ImageData, vec2u(ImageSize), 3); Image->FlipY(); Image->Write(OutputName); Log::Info("Rasterize to image took %.3f", sw.Stop()); }
CQuestionManager::Question CQuestionManager::GenOneQuestion() { Question ques = { { 0 }, 0 }; CFileListManager &file_manager = GetInst( CFileListManager ); int r = 0; // alpha image CImage img_alpha; CreateImgFromBuffer( file_manager.GetAlpha(), img_alpha ); // 1.generate the background. CImage back; CreateImgFromBuffer( file_manager.GetRandBack(), back ); r = random( 3 ); CImage *img_cover; for( int i = 0; i < r; ++ i ) { img_cover = MP_NEW CImage(); CreateImgFromBuffer( file_manager.GetRandBack(), *img_cover ); back.AlphaBlend( img_cover, 0, 0, ( random( 55 ) + 100 ) / 255.0f ); MP_DELETE(img_cover); } // 2.generate small pictures. ques.answer = BlendSmallImage( back, img_alpha ); // 3.covert the image to raw buffer. if( !back.ExportJpegToMemory( (BYTE*&) ques.data.buf, (DWORD&) ques.data.size, 85 ) ) { ques.data.buf = 0; ques.data.size = 0; PutoutLog( LOG_FILE, LT_ERROR, "Export jpeg failed." ); } DumpImage( &back ); return ques; }
bool LoadPicture(CImage& bmp, UINT nImgID, LPCTSTR lpImgType) //含Alpha通道的图片处理成CImage { LoadImageFromResourse(&bmp, nImgID, lpImgType); //加载图片资源 if (bmp.IsNull()) { return false; } if(bmp.GetBPP() == 32) //确认该图片包含Alpha通道 { for (int i=0; i < bmp.GetWidth(); i++) { for(int j=0; j < bmp.GetHeight(); j++) { byte* pByte = (byte*)bmp.GetPixelAddress(i, j); pByte[0] = pByte[0] * pByte[3] / 255; pByte[1] = pByte[1] * pByte[3] / 255; pByte[2] = pByte[2] * pByte[3] / 255; } } } return true; }
void CVisionTestDlg::ShowViewports() { for (int i=0; i<MAX_CHANNELS ; i++ ) { if ( m_Channels[i].bEnabled ) { CImage * img; img = new CImage(); switch ( m_Channels[i].unBpp ) { case 1: // TODO: break; case 8: if (m_Channels[i].bIndexed) img->CreateFromIndexed8BPP( m_Channels[i].unWidth, m_Channels[i].unHeight, m_Channels[i].pBuffer ); else img->CreateFromGray( m_Channels[i].unWidth, m_Channels[i].unHeight, m_Channels[i].pBuffer ); break; case 32: img->CreateFromRGB( m_Channels[i].unWidth, m_Channels[i].unHeight, m_Channels[i].pBuffer ); break; } // Copy the image to the dialog and show it m_Channels[i].pImageDialog->AddImage( *img ); m_Channels[i].pImageDialog->ShowWindow( SW_SHOW ); // Since the image is fully copied, we won't need it anymore. delete img; } } }
//重画消息 VOID CWebPublicize::OnPaint() { CPaintDC dc(this); //获取位置 CRect rcClient; GetClientRect(&rcClient); //创建缓冲 CImage ImageBuffer; ImageBuffer.Create(rcClient.Width(),rcClient.Height(),32); //绘画缓冲 CDC * pBufferDC=CDC::FromHandle(ImageBuffer.GetDC()); DrawPublicizeView(pBufferDC,rcClient.Width(),rcClient.Height(),m_cbStatus); //绘画界面 dc.BitBlt(0,0,rcClient.Width(),rcClient.Height(),pBufferDC,0,0,SRCCOPY); //释放资源 ImageBuffer.ReleaseDC(); return; }
// ------------------------------------------------------ // Benchmark: FAST // ------------------------------------------------------ double feature_extraction_test_FAST( int N, int h ) { CTicTac tictac; // Generate a random image CImage img; getTestImage(0,img); CFeatureExtraction fExt; CFeatureList featsFAST; fExt.options.featsType = featFAST; fExt.options.FASTOptions.threshold = 20; fExt.options.patchSize = 0; img.grayscaleInPlace(); tictac.Tic(); for (int i=0;i<N;i++) fExt.detectFeatures( img, featsFAST ); const double T = tictac.Tac()/N; return T; }
void ESChildControlDealer::OnPaintClient(CDC* pDC, CRect* pRectDC, CRect* pRectClient){ PokerGUI* pGUI = PokerGUI::GetInstance(); CImage* pImage = pGUI->m_pDealerBtnImg; if( !pImage ) return; CRect rcDealer; rcDealer.left = m_rcRect.left + (m_rcRect.Width() - pImage->GetWidth()) / 2; rcDealer.top = m_rcRect.top + (m_rcRect.Height() - pImage->GetHeight()) / 2; rcDealer.right = rcDealer.left + pImage->GetWidth(); rcDealer.bottom = rcDealer.top + pImage->GetHeight(); CRect rcDealerBtnDC, rcInvalid; rcDealerBtnDC.left = (rcDealer.left - pRectClient->left) + pRectDC->left; rcDealerBtnDC.top = (rcDealer.top - pRectClient->top) + pRectDC->top; rcDealerBtnDC.right = rcDealerBtnDC.left + rcDealer.Width(); rcDealerBtnDC.bottom = rcDealerBtnDC.top + rcDealer.Height(); // Draw button background. {{ rcInvalid = rcDealerBtnDC & *pRectDC; if( pImage && !rcInvalid.IsRectEmpty() ) PokerGUI::RenderImage(pDC, rcInvalid, rcDealerBtnDC, pImage); // }} }
void CChartCtrl::SaveAsImage(const TChartString& strFilename, const CRect& rect, int nBPP, REFGUID guidFileType) { CImage chartImage; CRect chartRect = rect; if (chartRect.IsRectEmpty()) { GetClientRect(&chartRect); } chartImage.Create(chartRect.Width(), chartRect.Height(), nBPP); CDC newDC; newDC.Attach(chartImage.GetDC()); DrawBackground(&newDC, chartRect); chartRect.DeflateRect(3,3); DrawChart(&newDC, chartRect); newDC.Detach(); chartImage.Save(strFilename.c_str(), guidFileType); chartImage.ReleaseDC(); }
CImage *AquireImage( HINSTANCE hInstance, LPCTSTR pcszFilePath, LPCTSTR pcszFilename ) { CImage *pImage = NULL; // // Check for resource based images if( !_tcsnicmp( pcszFilename, _T("RES:"), 4 ) ) { pcszFilename += 4; ASSERT( _tcslen( pcszFilename ) ); pImage = new CImage; if( !pImage->Load( hInstance, pcszFilename ) ) { LPTSTR endptr; if( !pImage->Load( hInstance, MAKEINTRESOURCE( _tcstol( pcszFilename, &endptr, 10 ) ) ) ) { delete pImage; pImage = NULL; } } return pImage; } // // Check for file based images StringClass strImageName( pcszFilePath ); strImageName += pcszFilename ; pImage = new CImage; if( !pImage->Load( strImageName ) ) { delete pImage; pImage = NULL; } return pImage; }
//绘画头像 void __cdecl CUserFaceRes::DrawCustomBigFace(CDC * pDC, int nXPos, int nYPos, DWORD dwUserID, DWORD dwCustomFace,UINT nWidth,UINT nHeight) { ASSERT(dwUserID!=0 && dwCustomFace!=0); if(!(dwUserID!=0 && dwCustomFace!=0))return; //头像名称 CString strDirName; strDirName.Format(TEXT("%s\\CustomFace"),m_szDirWork); CString strFileName; strFileName.Format(TEXT("\\%ld_%d.bmp"), dwUserID, dwCustomFace); //读取文件 CImage FaceImage; HRESULT hResult = FaceImage.Load(strDirName + strFileName); if (SUCCEEDED(hResult)) { //设置模式 int nOldBltMode = pDC->SetStretchBltMode(HALFTONE); //设置大小 CRect rcFace; rcFace.left = nXPos; rcFace.top = nYPos; rcFace.right = rcFace.left + nWidth; rcFace.bottom = rcFace.top + nHeight; //绘画图片 FaceImage.StretchBlt(pDC->GetSafeHdc(), rcFace); //删除资源 pDC->SetStretchBltMode(nOldBltMode); FaceImage.Destroy(); } return; }
// 从内存加载图片 BOOL ReadImage(const BYTE* buffer, ULONG size, CImage& img) { // 创建流 HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED, size); if (m_hMem == NULL) return FALSE; BYTE* pmem = (BYTE*)GlobalLock(m_hMem); if (pmem == NULL) return FALSE; memcpy(pmem, buffer, size); IStream* pstm = NULL; if (FAILED(CreateStreamOnHGlobal(m_hMem, FALSE, &pstm)) || pstm == NULL) return FALSE; // 加载到CImage if (!img.IsNull()) img.Destroy(); img.Load(pstm); // 释放流 GlobalUnlock(m_hMem); pstm->Release(); return !img.IsNull(); }
CImage* CTextRender::render( std::string text, int outline ) { int width = fontSize * text.length(); int height = fontSize; CImage* textSurface = new CImage( width, height ); textSurface->convert( *font ); // blit the letters for ( size_t i = 0; i < text.length(); i++ ) { char c = text.at(i); if ( 'a' <= c && c <= 'z' ) c -= 32; int glyphIndex = fontLetters.find(c); if ( glyphIndex == -1 ) glyphIndex = 60; CRect sRect; CRect dRect; // source rect sRect.w = sRect.h = fontSize; sRect.x = glyphIndex * fontSize; sRect.y = (1 - outline ) * fontSize; // destination position dRect.x = i * fontSize; dRect.y = 0; textSurface->blit( *font, dRect, sRect ); } return textSurface; }
/* RedoPop() */ BOOL CWallBrowserStretchView::RedoPop(void) { BOOL bRedo = FALSE; if(m_nRedo!=-1) { CWallBrowserDoc* pDoc = (CWallBrowserDoc*)GetDocument(); if(pDoc) { CImage *pImage = pDoc->GetImage(); if(pImage && pImage->GetWidth() > 0 && pImage->GetHeight() > 0) { bRedo = DoImageOperation(m_nRedo)==NO_ERROR; m_nRedo = -1; } } } CWnd* pWnd = AfxGetMainWnd(); if(pWnd) pWnd->PostMessage(WM_EDIT_REDO,RedoEnabled(),0L); return(bRedo); }
double feature_extraction_test_FASTER( int N, int threshold ) { CTicTac tictac; // Generate a random image CImage img; getTestImage(0,img); CFeatureExtraction fExt; CFeatureList feats; fExt.options.featsType = TYP; // FASTER_N==9 ? featFASTER9 : (FASTER_N==10 ? featFASTER10 : featFASTER12 ); fExt.options.FASTOptions.threshold = threshold; //20; fExt.options.patchSize = 0; img.grayscaleInPlace(); tictac.Tic(); for (int i=0;i<N;i++) fExt.detectFeatures( img, feats,0, MAX_N_FEATS ); const double T = tictac.Tac()/N; return T; }
void Draw_AmriSeedPointDirections() { string output_path = gConfig.GetOutputPath(); string image_name = gConfig.GetImageName(); string file_name; CImage* XY = NULL; CPoint pPoint; XY = new CImage(*CanvasXY); XY->RemovePixels(5); list<CPoint>::iterator i; for (i = AmriVerifiedSeedsCenter.begin(); i != AmriVerifiedSeedsCenter.end(); i++) { pPoint = *i; XY->MarkCrosshairXY(&pPoint, 0); CPoint temp; for (int j = 0; j < 5; j++) { CPoint* dirPoint =& gVectorsArray[pPoint.m_iHDir][0]-> m_pIndices[j]; temp.m_iX = pPoint.m_iX + dirPoint->m_iX; temp.m_iY = pPoint.m_iY + dirPoint->m_iY; temp.m_iZ = pPoint.m_iZ; if (The3DImage->WithinImagePadding(temp, giMARGIN)) XY->MarkPointXY(&temp, 1); else break; } } file_name = output_path + image_name + "AmriSeedDirectionsXY.tif"; XY->WriteTIFF(file_name); }