Exemple #1
0
//处理图片
bool CRichEditMessage::LoadRichEditImage(HINSTANCE hInstance, UINT uResourceID, CDataObject&ImageDataObject)
{
	//加载图片
	CBitImage ImageFile;
	ImageFile.LoadFromResource(hInstance,uResourceID);

	//失败判断
	if (ImageFile.IsNull()==true)
	{
		ASSERT(FALSE);
		return false;
	}

	//创建表情
	CImage ImageRichEdit;
	ImageRichEdit.Create(ImageFile.GetWidth(),ImageFile.GetHeight(),32);

	//绘画表情
	CDC * pDC=CDC::FromHandle(ImageRichEdit.GetDC());
	pDC->FillSolidRect(0,0,ImageFile.GetWidth(),ImageFile.GetHeight(),m_crFillColor);
	ImageFile.TransDrawImage(pDC,0,0,RGB(255,0,255));

	//设置图片
	ImageRichEdit.ReleaseDC();
	ImageDataObject.SetImage(ImageRichEdit.Detach());

	return true;
}
Exemple #2
0
bool CozyCaptureWindow::SendImageToClipboard(CImage &Img)
{
    if (OpenClipboard())
    {
        HBITMAP hbitmap_dib = Img.Detach();
        if (!hbitmap_dib)
        {
            return false;
        }

        DIBSECTION ds;
        ::GetObject(hbitmap_dib, sizeof(DIBSECTION), &ds);
        ds.dsBmih.biCompression = BI_RGB;

        HDC hdc             = ::GetDC(NULL);
        HBITMAP hbitmap_ddb = ::CreateDIBitmap(hdc, &ds.dsBmih, CBM_INIT, ds.dsBm.bmBits, (BITMAPINFO*)&ds.dsBmih, DIB_RGB_COLORS);
        ::ReleaseDC(NULL, hdc);

        ::EmptyClipboard();
        ::SetClipboardData(CF_BITMAP, hbitmap_ddb);
        ::CloseClipboard();
        return true;
    }
    return false;
}
void CbehaviorView::LoadImage()
{
	HBITMAP hBitmap;  
	CString filename;  
	CString BMPFolder;  
	CString str;  

	CImage layerPng;  

	//str.Format("layer (%d).png", layernum);  

	//filename = BMPFolder + "\\" + str;  
	filename = "D:\\fish_editor\\mini_hammer-master\\workplace\\media\\fish_base\\plist\\8goldItem.png";

	layerPng.Load(filename);  
	hBitmap=layerPng.Detach();  
	CBitmap bmp;  
	BITMAP l_bitMap;  
	bmp.Attach(hBitmap);  
	bmp.GetBitmap(&l_bitMap);  

	int height = l_bitMap.bmHeight;  
	int width = l_bitMap.bmWidth;  

	bmp.GetBitmapBits(128 * 128 * 4, m_lpBuf);
}
Exemple #4
0
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;
}
Exemple #5
0
//输入解释
void CExpressionItem::InitExpressItem(LPCTSTR pszChineseName, LPCTSTR pszTrancelate, UINT uIDResource)
{
	//设置变量
	m_uImageID=uIDResource;
	lstrcpyn(m_szTrancelate,pszTrancelate,CountArray(m_szTrancelate));
	lstrcpyn(m_szChineseName,pszChineseName,CountArray(m_szChineseName));
	m_wTranceLength=lstrlen(m_szTrancelate);

	//加载图片
	CSkinImage ImageFile;
	ImageFile.LoadFromResource(GetModuleHandle(CLIENT_SHARE_DLL_NAME),uIDResource);

	//创建表情
	CImage ImageExpression;
	ASSERT(ImageFile.GetWidth()==EP_PIC_WHIDE);
	ASSERT(ImageFile.GetHeight()==EP_PIC_HIGHT);
	ImageExpression.Create(EP_PIC_WHIDE,EP_PIC_HIGHT,32);

	//绘画表情
	CDC * pDC=CDC::FromHandle(ImageExpression.GetDC());
	pDC->FillSolidRect(0,0,EP_PIC_WHIDE,EP_PIC_HIGHT,COLOR_CHAR_BK);
	ImageFile.AlphaDrawImage(pDC,0,0,RGB(255,0,255));

	//设置图片
	ImageExpression.ReleaseDC();
	m_ImageDataObject.SetImage(ImageExpression.Detach());

	return;
};
Exemple #6
0
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;
}
HBITMAP LoadBmpFromImageFile(LPCTSTR lpszFileName)
{
    HBITMAP hBitmap = NULL;
    //Gdiplus::Bitmap bmp(lpszFileName, false);
    CImage image;
    image.Load(lpszFileName);
    hBitmap = image.Detach();
    return hBitmap;
}
Exemple #8
0
BOOL CEn_Bitmap::LoadImage(LPCTSTR szImagePath, COLORREF crBack)
{
	ASSERT(m_hObject == NULL);      // only attach once, detach on destroy

	if (m_hObject != NULL)
		return FALSE;

	// If GDI+ is available, use that API because it supports more file formats and images with alpha channels.
	// That DLL is installed with WinXP is available as redistributable from Microsoft for Win98+. As this DLL
	// may not be available on some OS but we have to link statically to it, we have to take some special care.
	//
	// NOTE: Do *NOT* forget to specify /DELAYLOAD:gdiplus.dll as link parameter.
	static int _bGdiPlusInstalled = -1;
	if (_bGdiPlusInstalled == -1)
	{
		_bGdiPlusInstalled = 0;
		HMODULE hLib = LoadLibrary(_T("gdiplus.dll"));
		if (hLib != NULL)
		{
			_bGdiPlusInstalled = GetProcAddress(hLib, "GdiplusStartup") != NULL;
			FreeLibrary(hLib);
		}
	}
	if (_bGdiPlusInstalled > 0)
	{
		CImage img;
		if (SUCCEEDED(img.Load(szImagePath)))
		{
			CBitmap::Attach(img.Detach());
			return TRUE;
		}
	}

	BOOL bResult = FALSE;
	CFile			cFile;
	CFileException	e;
	
	if (cFile.Open(szImagePath, CFile::modeRead | CFile::typeBinary | CFile::shareDenyWrite, &e))
	{
		int nSize = (int)cFile.GetLength();
		BYTE* pBuff = new BYTE[nSize];
		if (cFile.Read(pBuff, nSize) > 0)
		{
			IPicture* pPicture = LoadFromBuffer(pBuff, nSize);
			
			if (pPicture)
			{
				bResult = Attach(pPicture, crBack);
				pPicture->Release();
			}
		}
		delete [] pBuff;
	}

	return bResult;
}
Exemple #9
0
void Utils::SaveBitmapToFile(CBitmap * bmp)
{
	CImage image;
	CString Path;
	
	Path.Format("C:\\test%d.bmp", counter);
    image.Attach(*bmp);

    image.Save(Path, Gdiplus::ImageFormatBMP);
	image.Detach();
	counter++;
}
Exemple #10
0
HRESULT BMPanvas::SaveImage(CString name)
{
    HRESULT ret = E_FAIL;
    CImage TI;
    if(HasImage())
    {
        TI.Attach(GetHBMP(BMP_DETACH));
        ret=TI.Save(name,ImageFormatPNG);
        Attach(TI.Detach());
    }
    return ret;
}
Exemple #11
0
// Load bitmap from image file.
bool CMyStatic::LoadFromFile(LPCTSTR lpszFileName)
{
	bool bRet = false;
	if (lpszFileName && *lpszFileName)
	{
		CImage Image;
		bRet = SUCCEEDED(Image.Load(lpszFileName));
		if (bRet)
			bRet = ReplaceBitmap(Image.Detach());
	}
	return bRet;
}
Exemple #12
0
LRESULT CChildView::OnHPTimer(WPARAM wParam, LPARAM)
{
    // Get the screen region to copy.
    //
    CRect rect(MeaToolMgr::Instance().GetRegion());

    // Create a memory context and bitmap for it.
    //
    HDC screenDC = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
    HDC memDC = ::CreateCompatibleDC(screenDC);

    HBITMAP screenBitmap = ::CreateCompatibleBitmap(screenDC, rect.Width(), rect.Height());
    ::SelectObject(memDC, screenBitmap);

    // Copy the screen region to the bitmap.
    //
    ::BitBlt(memDC, 0, 0, rect.Width(), rect.Height(),
        screenDC, rect.left, rect.top, SRCCOPY);

	if((MeaTimer *)wParam == &m_screenGrabTimer)
	{
		// Save bitmap to file
		//
		CImage  img;

		CTime currentTime = CTime::GetCurrentTime();
		CString newFilename = currentTime.Format(_T("Grab %Y-%m-%d %H.%M.%S"));

		CString filePath = (m_screenGrabDirectory == _T("") ? m_screenGrabDirectory : m_screenGrabDirectory + _T("\\"));
		CString filename(filePath + newFilename + _T(".png"));

		img.Attach(screenBitmap);
		img.Save(filename);
		img.Detach();
	}
	else
	{
		// Put bitmap on the clipboard.
		//
		::EmptyClipboard();
		::SetClipboardData(CF_BITMAP, screenBitmap);
		::CloseClipboard();
	}

    // Cleanup
    //
    ::DeleteDC(screenDC);

    MeaToolMgr::Instance().EnableRadioTool();

    return 0;
}
Exemple #13
0
//******************************************
HRESULT BMPanvas::LoadImage( CString name )
{
    HRESULT ret;
    CImage TI;
    if((ret=TI.Load(name))==S_OK)
    {
        HDC thdc=TI.GetDC();
        hdc=CreateCompatibleDC(thdc);
        TI.ReleaseDC();
        if(hdc!=NULL)
        {
            Attach(TI.Detach());
            FileName=name;
        }
    }
    return ret;
}
Exemple #14
0
BOOL CEnBitmap::LoadImage(LPCTSTR szImagePath, COLORREF crBack)
{
	ASSERT(m_hObject == NULL);      // only attach once, detach on destroy

	if (m_hObject != NULL)
		return FALSE;

	// If GDI+ is available, use that API because it supports more file formats and images with alpha channels.
	// That DLL is installed with WinXP is available as redistributable from Microsoft for Win98+. As this DLL
	// may not be available on some OS but we have to link statically to it, we have to take some special care.
	//
	extern bool g_bGdiPlusInstalled;
	if (g_bGdiPlusInstalled)
	{
		CImage img;
		if (SUCCEEDED(img.Load(szImagePath)))
		{
			CBitmap::Attach(img.Detach());
			return TRUE;
		}
	}

	BOOL bResult = FALSE;
	CFile			cFile;
	CFileException	e;
	
	if (cFile.Open(szImagePath, CFile::modeRead | CFile::typeBinary | CFile::shareDenyWrite, &e))
	{
		int nSize = (int)cFile.GetLength();
		BYTE* pBuff = new BYTE[nSize];
		if (cFile.Read(pBuff, nSize) > 0)
		{
			IPicture* pPicture = LoadFromBuffer(pBuff, nSize);
			
			if (pPicture)
			{
				bResult = Attach(pPicture, crBack);
				pPicture->Release();
			}
		}
		delete [] pBuff;
	}

	return bResult;
}
Exemple #15
0
//加载图片
bool CImageDataObject::LoadImage(LPCTSTR pszFileName)
{
	//加载图片
	CImage Image;
	Image.Load(pszFileName);

	//结果判断
	if (Image.IsNull()==true)
	{
		ASSERT(FALSE);
		return false;
	}

	//设置图片
	SetImage(Image.Detach());

	return true;
}
Exemple #16
0
//加载图片
bool CDataObject::LoadImage(HINSTANCE hInstance, LPCTSTR lpResourceName)
{
	//加载图片
	CImage Image;
	Image.LoadFromResource(hInstance,lpResourceName);

	//结果判断
	if (Image.IsNull()==true)
	{
		ASSERT(FALSE);
		return false;
	}

	//设置图片
	SetImage(Image.Detach());

	return true;
}
Exemple #17
0
// クリップボードからビットマップを取得する関数
void SampleClipboard()
{
    if(!::IsClipboardFormatAvailable(CF_BITMAP))
    {
        return;
    }

    if(!::OpenClipboard(NULL))
    {
        return;
    }

    CImage image;
    HBITMAP hBitmap = (HBITMAP)::GetClipboardData(CF_BITMAP);
    if(hBitmap == NULL)
    {
        ::CloseClipboard();
        return;
    }

    CImage clip;

    // 
    clip.Attach(hBitmap);

    // イメージを保持しているデバイス コンテキストを取得
    HDC hdc = clip.GetDC();

    setTextColor(hdc, RGB(255, 0, 0));
    RECT rec;
    rec.top = 50;
    rec.left = 10;
    rec.right = 290;
    rec.bottom = 100;
    DrawText(hdc, "2019/04/12 XX:XX:XX", -1, &rec, NULL);

    clip.Detach();
    clip.ReleaseDC();

    ::CloseClipboard();

    // そのままファイルに保存することも可能
    // clip.Save(L"sample.png");
}
//加载图片
bool CImageEditorControl::LoadEditImage(CImage & Image)
{
	//状态效验
	ASSERT(Image.IsNull()==false);
	if (Image.IsNull()==true) return false;

	//清理资源
	m_ImageSource.Destroy();

	//获取位置
	CRect rcClient;
	GetClientRect(&rcClient);

	//加载图片
	m_ImageSource.Attach(Image.Detach());

	//缩放比例
	if (((DOUBLE)rcClient.Width()/(DOUBLE)rcClient.Height())<((DOUBLE)m_ImageSource.GetWidth()/(DOUBLE)m_ImageSource.GetHeight()))
	{
		m_dZoomPercent=(DOUBLE)rcClient.Width()/(DOUBLE)m_ImageSource.GetWidth();
	}
	else
	{
		m_dZoomPercent=(DOUBLE)rcClient.Height()/(DOUBLE)m_ImageSource.GetHeight();
	}

	//设置大小
	m_SizeSource.SetSize(m_ImageSource.GetWidth(),m_ImageSource.GetHeight());
	m_SizeTarget.SetSize((INT)(m_SizeSource.cx*m_dZoomPercent),(INT)(m_SizeSource.cy*m_dZoomPercent));

	//选择区域
	INT nSelectArea=__min(m_SizeTarget.cx,m_SizeTarget.cy)*4/5L;
	m_rcImageSelect.SetRect((rcClient.Width()-nSelectArea)/2,(rcClient.Height()-nSelectArea)/2,(rcClient.Width()+nSelectArea)/2,(rcClient.Height()+nSelectArea)/2);

	//更新界面
	RedrawWindow(NULL,NULL,RDW_INVALIDATE|RDW_ERASE|RDW_ERASENOW);

	//事件通知
	ASSERT(m_pIImageEditorEvent!=NULL);
	if (m_pIImageEditorEvent!=NULL) m_pIImageEditorEvent->OnEventImageSelect(true,false);

	return true;
}
Exemple #19
0
void CPlayerStatusBar::SetStatusBitmap(UINT id)
{
    if (m_bmid == id) {
        return;
    }

    if (m_bm.m_hObject) {
        m_bm.DeleteObject();
    }
    if (id) {
        // We can't use m_bm.LoadBitmap(id) directly since we want to load the bitmap from the main executable
        CImage img;
        img.LoadFromResource(AfxGetInstanceHandle(), id);
        m_bm.Attach(img.Detach());
    }
    m_bmid = id;

    Invalidate();
    Relayout();
}
Exemple #20
0
void TabOne::OnBnClickedButton1()
{
	this->DragAcceptFiles(true);
	CFileDialog dlg(TRUE, _T("*.bmp"), NULL,
	OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY,
	_T("image files (*.bmp; *.jpg) |*.bmp;*.jpg|All Files (*.*)|*.*||"),NULL);
 
	dlg.m_ofn.lpstrTitle= _T("Open Image");
 
	if (dlg.DoModal() == IDOK) {
 
		CString path= dlg.GetPathName();

		
		countImage = 0;
		img0[countImage] = cvLoadImage(path);             // load the image
		
		cvSaveImage(savePath,img0[countImage]);

					
		CImage img;
		img.Load(path);
		m_PicCtrl.SetBitmap((HBITMAP)img.Detach());

		SetDlgItemTextA(IDC_EDIT1, "Please Click LEFT EYE critical points");

	}
		//MessageBox("Please Click LEFT EYE critical points!!!!!!", "Click Critical Points Selection",  MB_OK | MB_ICONEXCLAMATION);

	//cvSaveImage("K:\\Reka-Photo\\pil.jpg",img0[0]);
	  
		//cvNamedWindow(name, 1);
		
		//cvShowImage(name, img0[countImage]);
		
		//cvSetMouseCallback(name, mouseHandler);
		


		//MessageBox("Please Click EYES critical points!!!!!!","Click Critical Points",MB_OK);
}
Exemple #21
0
// CCreateSeamlessMapDlg 消息处理程序
void CCreateSeamlessMapDlg::OnStnClickedStaticDefaultPng()
{
	// TODO: 在此添加控件通知处理程序代码
	CSelectSurfaceTextureDlg dlg;
	dlg.m_strInitSelectedFileName = m_strMaterial;
	if( dlg.DoModal() == IDOK )
	{
		m_strMaterial = dlg.getCurrentSelectedTexFile();

		CStatic* pStatic = (CStatic*)GetDlgItem( IDC_STATIC_DEFAULT_PNG );
		if( pStatic != NULL )
		{
			CString strTemp;
			strTemp.Format( "images/%s", m_strMaterial );

			CImage image;
			image.Load( strTemp );
			pStatic->SetBitmap( image.Detach() );
		}
	}
}
Exemple #22
0
BOOL CCreateSeamlessMapDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	GetPrivateProfileString( _T("init"), "surfaceTex1", _T(""), m_strMaterial.GetBuffer( MAX_PATH ), MAX_PATH, _T("./Editor/MapBlock.ini") );

	CStatic* pStatic = (CStatic*)GetDlgItem( IDC_STATIC_DEFAULT_PNG );
	if( pStatic != NULL )
	{
		CString strTemp;
		strTemp.Format( "images/%s", m_strMaterial );

		CImage image;
		image.Load( strTemp );
		pStatic->SetBitmap( image.Detach() );
	}


	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}
bool
EmbedeedFontMan::AddFont(const CString sFontFolder, const CString sFontName){
	CString sDir = sFontFolder;
	if( sDir.GetAt(sDir.GetLength() - 1) != '\\' )
		sDir += _T("\\");

	EmbedeedFont* pFont = new EmbedeedFont();

	// Load characters code map. {{
	BYTE*	lpContent	= NULL;
	int		nSize		= 0;
	if( Path::ReadFileContent(sDir + _T("codes.txt"), lpContent, nSize) && nSize > 0 ){
		CString sContent;
		memcpy(sContent.GetBufferSetLength(nSize), lpContent, nSize);

		CStringArray arrStrings;
		StringHelper::Split(&sContent, _T(";"), arrStrings);

		CString sCharCode;
		for(int i=0; i<arrStrings.GetCount(); i++){
			sCharCode		= arrStrings.GetAt(i);
			int nCharCode	= 0;
			// Hex value
			if( sCharCode.GetAt(0) == '#' )
				nCharCode = StringHelper::HexStringIntoInt(&((TCHAR*)sCharCode.GetBuffer())[1], sCharCode.GetLength() - 1);
			else
				nCharCode = _ttoi(sCharCode.GetBuffer());
			pFont->m_arrCharacters.Add((void*)nCharCode, (void*)i);
			}
		}
	else{
#ifdef _DEBUG
		CString sMsg;
		sMsg.Format(_T("Couldn't find %s"), sDir + _T("codes.txt"));
		AfxMessageBox(sMsg);
#endif
		if( lpContent )
			delete [] lpContent;
		delete pFont;
		return false;
		}
	// }}

	if( lpContent ){
		delete [] lpContent;
		lpContent = NULL;
		}

	CStringArray arrFileNames;
	if( Path::GetFilesByExtention(sDir, _T("*.bmp"), arrFileNames, true) == 0 ){
		delete pFont;
		return false;
		}
	
	for(int i=0; i<arrFileNames.GetCount(); i++){
		CString sName = arrFileNames.GetAt(i);
		CString sName2 = sName;
		CString sFile = sDir + sName;

		if( sName.Left(sFontName.GetLength()) != sFontName )
			continue; // Skip wrong file name.

		sName.Delete	(0, sFontName.GetLength());
		sName.MakeLower	();

		int nIndex = 0;
		EmbedeedFontItemInfo* pInfo = new EmbedeedFontItemInfo();
		pInfo->ZeroInit();

		// Bold
		if( sName.GetAt(nIndex) == 'b' ){
			pInfo->m_nCharFlags |= EmbedeedFontItemInfo::EMBEDEED_FONT_FLAG_BOLD;
			nIndex ++;
			}
		// Underline
		if( sName.GetAt(nIndex) == 'u' ){
			pInfo->m_nCharFlags |= EmbedeedFontItemInfo::EMBEDEED_FONT_FLAG_UNDERLINE;
			nIndex ++;
			}
		// Italic
		if( sName.GetAt(nIndex) == 'i' ){
			pInfo->m_nCharFlags |= EmbedeedFontItemInfo::EMBEDEED_FONT_FLAG_ITALIC;
			nIndex ++;
			}

		// Load characters map image and detect characters left offset and width (in pixels). {{
		CImage* pImage = ImageHelper::LoadImage(sFile, -1, -1, false);
		if( pImage ){
			BITMAP bmImage;
			GetObject(*pImage, sizeof(BITMAP), &bmImage);

			int			nWidthLimit				= bmImage.bmWidth;
			int			nSymbolCt				= 0;
			BYTE*		pBits					= (BYTE*)bmImage.bmBits;
			int			nXOffset				= 0;
			int			nBPP					= bmImage.bmBitsPixel/8;
			int			nSymbolMostLeftOffset	= -1;
			int			nSymbolMostRightOffset	= -1;
			CDWordArray arrSymbolLeftOffsetAndWidth;
			CString		sSymbolStartPointAndWidth;

			int nMaxXOffset = bmImage.bmWidth;
			for(int x=nXOffset; x<nMaxXOffset; x++){
				bool bClearLine = true;
				for(int y=0; y<bmImage.bmHeight; y++){
					BYTE* pLineStartingBits = &pBits[((bmImage.bmHeight - y - 1)*bmImage.bmWidthBytes)];
					BYTE* pPixel			= &pLineStartingBits[x*nBPP];

					// Is pixel visible.
					if( pPixel[0] > 10 ){
						bClearLine = false;
						if( nSymbolMostLeftOffset > -1 )
							nSymbolMostRightOffset = x;
						else
							nSymbolMostLeftOffset = x;
						continue;
						}
		
					pPixel = &pPixel[nBPP];
					}

				if( bClearLine && nSymbolMostLeftOffset > -1 ){
					if( nSymbolMostRightOffset == -1 )
						nSymbolMostRightOffset = nSymbolMostLeftOffset;
					DWORD dwCombineVal = (nSymbolMostLeftOffset << 16) | ((nSymbolMostRightOffset - nSymbolMostLeftOffset + 1)&0xFFFF);
					arrSymbolLeftOffsetAndWidth.Add(dwCombineVal);

#ifdef _DEBUG
					CString sFormat;
					sFormat.Format(_T("%d:%d;"), nSymbolMostLeftOffset, nSymbolMostRightOffset - nSymbolMostLeftOffset + 1);
					sSymbolStartPointAndWidth += sFormat;
#endif
					nSymbolMostLeftOffset	= -1;
					nSymbolMostRightOffset	= -1;
					}
				}

			pInfo->m_imageCharacters.Attach(pImage->Detach());
			delete pImage;

			if( (arrSymbolLeftOffsetAndWidth.GetCount() == pFont->m_arrCharacters.GetCount()) ){
				pInfo->m_pCharPoints = new CPoint[arrSymbolLeftOffsetAndWidth.GetCount()];
				for(int j=0; j<arrSymbolLeftOffsetAndWidth.GetCount(); j++){
					DWORD dwCombineVal = arrSymbolLeftOffsetAndWidth.GetAt(j);
					pInfo->m_pCharPoints[j].x = (int)(dwCombineVal>>16);
					pInfo->m_pCharPoints[j].y = (int)(dwCombineVal&0xFFFF);
					}
				}
			else{
#ifdef _DEBUG
				CBitmap bmImg;
				ImageHelper::CreateDIBBitmap(pInfo->m_imageCharacters.GetBPP(), bmImg, RGB(0, 0, 0), pInfo->m_imageCharacters.GetWidth(),
					pInfo->m_imageCharacters.GetHeight()*2, 0);

				CDC memDC;
				memDC.CreateCompatibleDC(NULL);
				::SelectObject(memDC, bmImg.m_hObject);

				CDC srcDC;
				srcDC.CreateCompatibleDC(NULL);
				::SelectObject(srcDC, pInfo->m_imageCharacters);
				memDC.BitBlt(0, 0, pInfo->m_imageCharacters.GetWidth(), pInfo->m_imageCharacters.GetHeight(), &srcDC, 0, 0, SRCCOPY);

				int nHeight = pInfo->m_imageCharacters.GetHeight();
				for(int j=0; j<arrSymbolLeftOffsetAndWidth.GetCount(); j++){
					DWORD dwCombineVal = arrSymbolLeftOffsetAndWidth.GetAt(j);
					int nLeft = (int)(dwCombineVal>>16);
					int nWidth = (int)(dwCombineVal&0xFFFF);

					memDC.FillSolidRect(nLeft, nHeight, nWidth, nHeight, RGB(255, 255, 0));
					}

				DeleteFile(sDir + _T("__") + sName2);
				CImage img;
				img.Attach((HBITMAP)bmImg.Detach());
				img.Save(sDir + _T("__") + sName2);
				img.Destroy();
				
				CString sMsg;
				sMsg.Format(_T("Characters count is not the same for font '%s' item '%s'"), sFontName, sName);
				AfxMessageBox(sMsg);
#endif
				delete pInfo;
				continue;
				}

			pInfo->m_nCharCount = arrSymbolLeftOffsetAndWidth.GetCount();
			}
Exemple #24
0
void CChildView::OnLButtonDown(UINT nFlags, CPoint point)
{
	m_Edit.ShowWindow(SW_HIDE);
	for (UINT i = 0; i < HotSpots.size(); i++)
	{
		if (HotSpots[i].Rect.PtInRect(point))
		{
			CNodeBase* pHitObject = (CNodeBase*)HotSpots[i].object;

			if (HotSpots[i].Type == HS_OPENCLOSE)
			{
				pHitObject->bOpen[HotSpots[i].Level] = !pHitObject->bOpen[HotSpots[i].Level];
			}
			else if (HotSpots[i].Type == HS_CLICK)
			{
				pHitObject->Update(HotSpots[i]);
			}
			else if (HotSpots[i].Type == HS_SELECT)
			{
				if (nFlags == MK_LBUTTON)
				{
					theApp.ClearSelection();
					Selected.clear();
					pHitObject->bSelected = true;
					Selected.push_back(HotSpots[i]);
				}
				if (nFlags == (MK_LBUTTON | MK_CONTROL))
				{
					pHitObject->bSelected = !pHitObject->bSelected;
					if (pHitObject->bSelected)
					{
						Selected.push_back(HotSpots[i]);
					}
					else
					{
						for (UINT s = 0; s < Selected.size(); s++)
						{
							if (Selected[s].object == pHitObject)
							{
								Selected.erase(Selected.begin() + s);
								break;
							}
						}
					}
				}
				if (nFlags == (MK_LBUTTON | MK_SHIFT))
				{
					if (Selected.size() > 0)
					{
						CNodeBase* pSelected = Selected[0].object;
						if (pSelected->pParent != pHitObject->pParent)
							continue;
						CNodeClass* pClass = (CNodeClass*)pSelected->pParent;
						//if (pClass->GetType() != nt_class) continue;

						UINT idx1 = FindNodeIndex(pSelected);
						if (idx1 == MAX_NODES)
							continue;
						UINT idx2 = FindNodeIndex(pHitObject);
						if (idx2 == MAX_NODES)
							continue;
						if (idx2 < idx1)
						{
							UINT idxTemp = idx1;
							idx1 = idx2;
							idx2 = idxTemp;
						}

						theApp.ClearSelection();
						Selected.clear();
						for (UINT s = idx1; s <= idx2; s++)
						{
							pClass->Nodes[s]->bSelected = true;
							HotSpot spot;
							//ZeroMemory(&spot, sizeof(HotSpot));
							spot.Address = pClass->offset + pClass->Nodes[s]->offset;
							spot.object = pClass->Nodes[s];
							Selected.push_back(spot);
						}
					}
				}
			}
			else if (HotSpots[i].Type == HS_DROP)
			{
				CRect client;
				GetClientRect(&client);
				ClientToScreen(&client);
				CMenu menu;
				menu.LoadMenu(MAKEINTRESOURCE(IDR_MENU_QUICKMODIFY));
				menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN | TPM_HORNEGANIMATION, client.left + HotSpots[i].Rect.left, client.top + HotSpots[i].Rect.bottom, this);
			}
			else if (HotSpots[i].Type == HS_DELETE)
			{
				//isDeleting = true; // Ghetto fix to stop crashing from OnMouseHover
				for (UINT i = 0; i < Selected.size(); i++)
				{
					CNodeClass* pClass = (CNodeClass*)Selected[i].object->pParent;
					UINT idx = FindNodeIndex(Selected[i].object);
					if (idx != MAX_NODES)
					{
						delete pClass->Nodes[idx];
						pClass->Nodes.erase(pClass->Nodes.begin() + idx);
						theApp.CalcAllOffsets();
					}
				}
				Selected.clear();
				//isDeleting = false;
			}
			else if ((HotSpots[i].Type == HS_CHANGE_A) || (HotSpots[i].Type == HS_CHANGE_X))
			{
				ExchangeTarget = HotSpots[i];
				CRect pos = ExchangeTarget.Rect;
				ClientToScreen(&pos);

				CNodeBase* pNode = HotSpots[i].object;

				CMenu menu;
				menu.CreatePopupMenu();

				CImage img;
				img.LoadFromResource(AfxGetResourceHandle(), IDB_CLASSBITMAP);
				CBitmap bmp;
				bmp.Attach(img.Detach());

				for (UINT m = 0; m < theApp.Classes.size(); m++)
				{
					if ((HotSpots[i].Type == HS_CHANGE_X) && (pNode->pParent == theApp.Classes[m]))
						continue;
					menu.AppendMenu(MF_STRING | MF_ENABLED, WM_CHANGECLASSMENU + m, theApp.Classes[m]->Name);
					menu.SetMenuItemBitmaps(m, MF_BYPOSITION, &bmp, &bmp);
				}
				menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_NOANIMATION, pos.left, pos.bottom, this);
			}
			Invalidate();
		}
	}

	CWnd::OnLButtonDown(nFlags, point);
}
void CDlgCapCam::UpdateImage(void)
{
	int i;
	CPen cur_pen, *old_pen=NULL;
	CBrush cur_brush,*old_brush = NULL;
	CPoint point;
	CSize size;
	CRect rect_image;
	CImage * pimage;
	CString str_dis;
	CRect client_rect1;
	CSize paint_size1;
	__time32_t l_time;

	if (!m_img_show.IsNull())
	{
		pimage = &m_img_show;
		_time32(&l_time);

		CWnd * pDis1 = GetDlgItem(IDC_STATIC_IMGSHOW);
		CDC* pDC1 = pDis1->GetDC();
		CDC MemDC1;
		CBitmap MemBitmap1;
		CPen pen_target;

		rect_image = CRect(0,0,pimage->GetWidth()-1, pimage->GetHeight()-1);
		pDis1->GetClientRect(&client_rect1);
		MemDC1.CreateCompatibleDC(pDC1);
		MemBitmap1.CreateCompatibleBitmap(pDC1,rect_image.Width(),rect_image.Height());
		MemDC1.SelectObject(&MemBitmap1);

		MemDC1.SetStretchBltMode(COLORONCOLOR);
		pDC1->SetStretchBltMode(COLORONCOLOR);

		pimage->BitBlt(MemDC1.GetSafeHdc(),rect_image, CPoint(0,0),SRCCOPY);

		//draw other osd targets
		pen_target.CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
		MemDC1.SelectStockObject(NULL_BRUSH);
		MemDC1.SelectObject(&pen_target);
		for (i=0; i<m_proc_result_buf.target_set.num; i++)
		{

			MemDC1.Rectangle(m_proc_result_buf.target_set.targets[i].rect.left,
				m_proc_result_buf.target_set.targets[i].rect.bottom,
				m_proc_result_buf.target_set.targets[i].rect.right,
				m_proc_result_buf.target_set.targets[i].rect.top);

		}

		//修改事件抓拍为每10秒钟1次
#define SNATCH_TIME_INTER 10
#define SNATCH_TIME_LATE	120

		time_t cur_time;
		struct tm * now_time;

		time(&cur_time);
		now_time = localtime(&cur_time);

		if (m_proc_result_buf.target_set.num > 0)
		{
			if (cur_time - m_trigger_snatch_time >= SNATCH_TIME_INTER)				
			{
				//超过10s间隔
				ScreenShot(1, SNATCH_TIME_INTER);

				m_trigger_snatch_time = cur_time;
			}
		}

		//延续120秒
		else if(m_trigger_snatch_time > 0 && cur_time - m_trigger_snatch_time <=SNATCH_TIME_LATE)
		{
			ScreenShot(SNATCH_TIME_LATE/SNATCH_TIME_INTER, SNATCH_TIME_INTER);
			m_trigger_snatch_time = 0;
		}


		if (!m_proc_result_buf.flg_used)
		{
			if (m_proc_result_buf.target_set.num)
			{
				((CSTEvaluationDlg*)pWndParent)->AddTarget(&m_proc_result_buf.target_set);
			}
			//do event
			for (i=0; i<m_proc_result_buf.event_set.num; i++)
			{
				//摄像头采集的,帧数置零
				((CSTEvaluationDlg*)pWndParent)->AddEvent(0,l_time,m_proc_result_buf.event_set.events[i].type);
				//同时触发抓拍
				//ScreenShot(12, 10);
			}

			//防止由于刷新,事件被触发两次
			m_proc_result_buf.flg_used = TRUE;
		}



		//---------------------抓拍的操作-------------------
		//if (WaitForSingleObject(m_proc_flgscreenshot, 0) == WAIT_OBJECT_0)
		if (m_snatch_count>0 && l_time - m_snatch_pretime>=m_snatch_intertime)
		{
			CImage img;
			CString str_name;
			time_t cur_time;
			struct tm * now_time;
			str_name = ((CSTEvaluationDlg*)pWndParent)->file_path;
			str_name += +_T("\\screenshot\\");
			time(&cur_time);
			now_time = localtime(&cur_time);
			str_name.AppendFormat(_T("_%012d_alarm.jpg"), cur_time);
			img.Attach(MemBitmap1);
			img.Save(str_name);
			img.Detach();

			m_snatch_count--;
			m_snatch_pretime = l_time;
		}

		pDC1->StretchBlt(0,0,STE_IMAGE_WIDTH*2-1,STE_IMAGE_HEIGH*2-1,&MemDC1,0,0,rect_image.Width()-1, rect_image.Height()-1, SRCCOPY);

		pDis1->ReleaseDC(pDC1);

	}
	else
	{
		pimage = &m_img_def;

		CWnd * pDis1 = GetDlgItem(IDC_STATIC_IMGSHOW);
		CDC* pDC1 = pDis1->GetDC();
		rect_image = CRect(0,0,pimage->GetWidth()-1, pimage->GetHeight()-1);	
		pDis1->GetClientRect(&client_rect1);
		pimage->StretchBlt(pDC1->GetSafeHdc(),client_rect1, rect_image, SRCCOPY);

		pDis1->ReleaseDC(pDC1);
	}

#ifdef _DEBUG
	if (!m_img1.IsNull())
	{
		pimage = &m_img1;

		//CWnd * pDis1 = GetDlgItem(IDC_STATIC_IMGSHOW);
		CDC* pDC1 = GetDC();
		rect_image = CRect(0,0,pimage->GetWidth()-1, pimage->GetHeight()-1);
		GetClientRect(&client_rect1);
		pimage->StretchBlt(pDC1->GetSafeHdc(),CRect(380,20, 380+175, 20+143), rect_image);
		//pimage->BitBlt(pDC1->GetSafeHdc(), 500,0,352,288, 0,0,SRCCOPY);
		ReleaseDC(pDC1);
	}
	if (!m_img2.IsNull())
	{
		pimage = &m_img2;

		//CWnd * pDis1 = GetDlgItem(IDC_STATIC_IMGSHOW);
		CDC* pDC1 = GetDC();
		rect_image = CRect(0,0,pimage->GetWidth()-1, pimage->GetHeight()-1);
		GetClientRect(&client_rect1);
		pimage->StretchBlt(pDC1->GetSafeHdc(),CRect(380,170, 380+175, 170+143), rect_image);
		//pimage->BitBlt(pDC1->GetSafeHdc(), 500,0,352,288, 0,0,SRCCOPY);
		ReleaseDC(pDC1);
	}
	if (!m_img3.IsNull())
	{
		pimage = &m_img3;

		//CWnd * pDis1 = GetDlgItem(IDC_STATIC_IMGSHOW);
		CDC* pDC1 = GetDC();
		rect_image = CRect(0,0,pimage->GetWidth()-1, pimage->GetHeight()-1);
		GetClientRect(&client_rect1);
		pimage->StretchBlt(pDC1->GetSafeHdc(),CRect(560,20, 560+175, 20+143), rect_image);
		//pimage->BitBlt(pDC1->GetSafeHdc(), 500,0,352,288, 0,0,SRCCOPY);
		ReleaseDC(pDC1);
	}
	if (!m_img4.IsNull())
	{
		pimage = &m_img4;

		//CWnd * pDis1 = GetDlgItem(IDC_STATIC_IMGSHOW);
		CDC* pDC1 = GetDC();
		rect_image = CRect(0,0,pimage->GetWidth()-1, pimage->GetHeight()-1);
		GetClientRect(&client_rect1);
		pimage->StretchBlt(pDC1->GetSafeHdc(),CRect(560,170, 560+175, 170+143), rect_image);
		//pimage->BitBlt(pDC1->GetSafeHdc(), 500,0,352,288, 0,0,SRCCOPY);
		ReleaseDC(pDC1);
	}	

#endif
	

	//因为帧数等信息和图像相关,所以也放在此处更新
	__time32_t n_time = 0;
	if (m_flg_process)
	{
		_time32(&n_time);
	}


	//str_dis.Format(_T("Frame:%06d;   Time(s):%06d"), m_proc_result_buf.frame_index, n_time-m_start_time);
	str_dis.Format(_T("Frame:%02d;   Time: %02dm:%02ds"), m_proc_result_buf.frame_index,
		(n_time-m_start_time)/60, 
		(n_time-m_start_time)%60);
	GetDlgItem(IDC_STATIC_STATUS)->SetWindowText(str_dis);
}
Exemple #26
0
void TabOne::OnLButtonDown(UINT nFlags, CPoint point)
{
	
	
		
	int poiX, poiY;
	int X, Y;
	X = point.x;
	Y = point.y;

	pt = cvPoint(X-280,Y-54);
	
	
	//poiX = X-poiX1;
	//poiY = Y-poiY1;

	CString str1;
	str1.Format("%d", X);

	CString str2;
	str2.Format("%d", Y);
	if ((nFlags & MK_LBUTTON) == MK_LBUTTON) {

		MessageBox("X:" + str1+  "Y:" + str2,"aaaaaaaaaaaa",MB_ICONSTOP|MB_OK);
		countImage++;
		//MessageBox(NULL,"X:" + str1 +"  Y:"+ str2 , "Click Critical Points Selection",  MB_OK | MB_ICONEXCLAMATION);
	
		
		
		
		img0[countImage] = cvCloneImage(img0[countImage-1]);
		
		cvCircle(img0[countImage], pt, 1, CV_RGB(0,255,0), -1, 8,0);
		//cvShowImage(name, img0[countImage]);
		cvSaveImage(savePath,img0[countImage]);

		CImage img;
		img.Load(savePath);
		m_PicCtrl.SetBitmap((HBITMAP)img.Detach());
		xCoordinate[countImage-1] = pt.x;
		yCoordinate[countImage-1] = pt.y;

		if(countImage>=4&& countImage<8)
			SetDlgItemTextA(IDC_EDIT1, "Please Click RIGHT EYE critical points");
			//MessageBox("Please Click RIGHT EYE critical points!!!!!!", "Click Critical Points Selection",  MB_OK | MB_ICONEXCLAMATION);

		if(countImage<11 && countImage >=8)
			SetDlgItemTextA(IDC_EDIT1, "Please Click NOSE critical points");
			//MessageBox("Please Click NOSE critical points!!!!!!", "Click Critical Points Selection",  MB_OK | MB_ICONEXCLAMATION);

		if(countImage>=11)
			SetDlgItemTextA(IDC_EDIT1, "Please Click MOUTH critical points");
			//MessageBox("Please Click MOUTH critical points!!!!!!", "Click Critical Points Selection",  MB_OK | MB_ICONEXCLAMATION);

		
		if(countImage == 16) {

			//insertionSort(xCoordinate, 15);
			//insertionSort(yCoordinate, 15);
		
			}


	}	

	
	//m_PicCtrl.
	if ((nFlags & MK_LBUTTON) == MK_LBUTTON){

		//MessageBox("X:" + str1+  "Y:" + str2,"Sorry, this is not a 24 Bit Bitmap.",MB_ICONSTOP|MB_OK);
		
		
  }

	if (nFlags == WM_LBUTTONDOWN) {
		MessageBox("bbbbbb","Sorry, this is not a 24 Bit Bitmap.",MB_ICONSTOP|MB_OK);
	}
	
	CWnd::OnLButtonDown(nFlags, point);

}
void 
MercuryScrollBar::OnPaintClient(CDC* pDC, CRect* pRectDC, CRect* pRectClient)
	{
	CRect	rcClient;
	GetClientRect(rcClient);
	if( rcClient.IsRectEmpty() || pRectClient->IsRectEmpty() ) 
		return;

	CRect	rcDestDC; // Full destination rect in DC coordinates.
	rcDestDC.left	= pRectDC->left - pRectClient->left;
	rcDestDC.top	= pRectDC->top - pRectClient->top;
	rcDestDC.right	= rcDestDC.left + rcClient.Width();
	rcDestDC.bottom	= rcDestDC.top + rcClient.Height();

	CBitmap bmBkgnd, bmpImg;
	ImageHelper::CreateBitmap32bpp(bmBkgnd, (COLORREF)0, rcClient.Width(), rcClient.Height());

	if( m_bVscroll ){
		// Draw top arrow. #########################################
		CRect rcDraw;
		rcDraw.left			= rcDestDC.left + m_rcArrowBtnTop.left;
		rcDraw.right		= rcDraw.left + m_rcArrowBtnTop.Width();
		rcDraw.top			= rcDestDC.top + m_rcArrowBtnTop.top;
		rcDraw.bottom		= rcDraw.top + m_rcArrowBtnTop.Height();
		CImage* pImage		= &m_pGUI->scrollBar.m_imgVScrollTopNormal;
		if( m_nHitTest == HITTEST_TOP_ARROW )
			pImage			= &m_pGUI->scrollBar.m_imgVScrollTopSel;
		
		bmpImg.Attach(pImage->Detach());
		ImgHlp::DrawBitmap32bppEx(&bmBkgnd, &bmpImg, &rcDraw, pRectDC, NULL, FALSE);
		pImage->Attach((HBITMAP)bmpImg.Detach());
		// #########################################################

		// Draw bottom arrow. ######################################
		rcDraw.left			= rcDestDC.left + m_rcArrowBtnBottom.left;
		rcDraw.right		= rcDraw.left + m_rcArrowBtnBottom.Width();
		rcDraw.top			= rcDestDC.top + m_rcArrowBtnBottom.top;
		rcDraw.bottom		= rcDraw.top + m_rcArrowBtnBottom.Height();
		if( m_nHitTest == HITTEST_BOTTOM_ARROW )
			pImage			= &m_pGUI->scrollBar.m_imgVScrollBottomSel;
		else
			pImage			= &m_pGUI->scrollBar.m_imgVScrollBottomNormal;

		bmpImg.Attach(pImage->Detach());
		ImgHlp::DrawBitmap32bppEx(&bmBkgnd, &bmpImg, &rcDraw, pRectDC, NULL, FALSE);
		pImage->Attach((HBITMAP)bmpImg.Detach());
		// #########################################################

		// Draw middle part. #######################################
		CRect rcMiddle	(m_rcArrowBtnTop.left, m_rcArrowBtnTop.bottom, 
						m_rcArrowBtnTop.right, m_rcArrowBtnBottom.top);
		rcDraw.left			= rcDestDC.left + m_rcArrowBtnTop.left;
		rcDraw.right		= rcDraw.left + m_rcArrowBtnTop.Width();
		rcDraw.top			= rcDestDC.top + m_rcArrowBtnTop.bottom;
		rcDraw.bottom		= rcDraw.top + rcMiddle.Height();
		pImage				= &m_pGUI->scrollBar.m_imgVScrollMiddle;

		bmpImg.Attach(pImage->Detach());
		ImgHlp::DrawBitmap32bppEx(&bmBkgnd, &bmpImg, &rcDraw, pRectDC, NULL, FALSE);
		pImage->Attach((HBITMAP)bmpImg.Detach());
		// #########################################################

		// Draw thumb. ##########################################
		pImage				= &m_pGUI->scrollBar.m_imgVScrollThumb;
		rcDraw.left			= rcDestDC.left + (rcDestDC.Width() - m_pGUI->scrollBar.m_imgVScrollThumb.GetWidth())/2;
		rcDraw.right		= rcDraw.left + m_pGUI->scrollBar.m_imgVScrollThumb.GetWidth();
		rcDraw.top			= rcDestDC.top + m_rcThumb.top;
		rcDraw.bottom		= rcDraw.top + m_rcThumb.Height();

		bmpImg.Attach(pImage->Detach());
		ImgHlp::DrawBitmap32bppEx(&bmBkgnd, &bmpImg, &rcDraw, pRectDC, &m_pGUI->scrollBar.m_rcOmitVScrollThumb, TRUE);
		pImage->Attach((HBITMAP)bmpImg.Detach());
		// ######################################################
		}
	else{
		// Draw left arrow. #########################################
		CRect rcDraw;
		rcDraw.left			= rcDestDC.left + m_rcArrowBtnLeft.left;
		rcDraw.right		= rcDraw.left + m_rcArrowBtnLeft.Width();
		rcDraw.top			= rcDestDC.top + m_rcArrowBtnLeft.top;
		rcDraw.bottom		= rcDraw.top + m_rcArrowBtnLeft.Height();
		CImage* pImage		= &m_pGUI->scrollBar.m_imgHScrollLeftNormal;
		if( m_nHitTest == HITTEST_LEFT_ARROW )
			pImage			= &m_pGUI->scrollBar.m_imgHScrollLeftSel;
		
		bmpImg.Attach(pImage->Detach());
		ImgHlp::DrawBitmap32bppEx(&bmBkgnd, &bmpImg, &rcDraw, pRectDC, NULL, FALSE);
		pImage->Attach((HBITMAP)bmpImg.Detach());
		// #########################################################

		// Draw middle part. #######################################
		CRect rcMiddle	(m_rcArrowBtnLeft.right, m_rcArrowBtnLeft.top, 
						m_rcArrowBtnRight.left, m_rcArrowBtnLeft.bottom);

		rcDraw.left			= rcDestDC.left + m_rcArrowBtnLeft.right;
		rcDraw.right		= rcDraw.left + rcMiddle.Width();
		rcDraw.top			= rcDestDC.top + m_rcArrowBtnLeft.top;
		rcDraw.bottom		= rcDraw.top + m_rcArrowBtnLeft.Height();
		pImage				= &m_pGUI->scrollBar.m_imgHScrollMiddle;

		bmpImg.Attach(pImage->Detach());
		ImgHlp::DrawBitmap32bppEx(&bmBkgnd, &bmpImg, &rcDraw, pRectDC, NULL, FALSE);
		pImage->Attach((HBITMAP)bmpImg.Detach());
		// #########################################################

		// Draw right arrow. ######################################
		rcDraw.left			= rcDestDC.left + m_rcArrowBtnRight.left;
		rcDraw.right		= rcDraw.left + m_rcArrowBtnRight.Width();
		rcDraw.top			= rcDestDC.top + m_rcArrowBtnRight.top;
		rcDraw.bottom		= rcDraw.top + m_rcArrowBtnRight.Height();
		if( m_nHitTest == HITTEST_RIGHT_ARROW )
			pImage			= &m_pGUI->scrollBar.m_imgHScrollRightSel;
		else
			pImage			= &m_pGUI->scrollBar.m_imgHScrollRightNormal;

		bmpImg.Attach(pImage->Detach());
		ImgHlp::DrawBitmap32bppEx(&bmBkgnd, &bmpImg, &rcDraw, pRectDC, NULL, FALSE);
		pImage->Attach((HBITMAP)bmpImg.Detach());
		// #########################################################

		// Draw thumb. ##########################################
		pImage				= &m_pGUI->scrollBar.m_imgHScrollThumb;
		rcDraw.left			= rcDestDC.left + m_rcThumb.left;
		rcDraw.right		= rcDraw.left + m_rcThumb.Width();
		rcDraw.top			= rcDestDC.top + (rcDestDC.Height() - m_pGUI->scrollBar.m_imgHScrollThumb.GetHeight())/2;
		rcDraw.bottom		= rcDraw.top + m_rcThumb.Height();

		bmpImg.Attach(pImage->Detach());
		ImgHlp::DrawBitmap32bppEx(&bmBkgnd, &bmpImg, &rcDraw, pRectDC, &m_pGUI->scrollBar.m_rcOmitHScrollThumb, TRUE);
		pImage->Attach((HBITMAP)bmpImg.Detach());
		// ######################################################
		}

	// From memory image to DC. ################################
	CDC memDC;
	memDC.CreateCompatibleDC(pDC);
	memDC.SelectObject(&bmBkgnd);

	if( !UseDoubleBufferedDC() )
		pDC->BitBlt(pRectClient->left, pRectClient->top, pRectClient->Width(), pRectClient->Height(), &memDC, 
					pRectClient->left, pRectClient->top, SRCCOPY);
	else
		pDC->BitBlt(0, 0, pRectClient->Width(), pRectClient->Height(), &memDC, 0, 0, SRCCOPY);
	
	memDC.DeleteDC();
	bmBkgnd.DeleteObject();
	// #########################################################
	}
int ImageTranscode_transcode_private(std::string filepath,
                                     ImageTranscode_ImageType type,
                                     size_t width,
                                     size_t height,
                                     unsigned char** out_image,
                                     size_t& out_image_len)
{
    int rc = IMAGE_TRANSCODING_OK;
    HRESULT result;
    HBITMAP hbitmap = NULL;
    wchar_t* tfilepath = NULL;
    unsigned char* buf = NULL;
    GUID raw_format_guid;
    Image* image = NULL;
    size_t org_width = 0;
    size_t org_height = 0;
    size_t max_wh_size = 0;
    double r1;
    double r2;
    Bitmap* bitmap;
    IStream* stream = NULL;
    CLSID clsid;
    ULONG quality = DEFAULT_COMPRESS_RATE;
    Status saveStatus;

    if (width == 0 || height == 0) {
        return IMAGE_TRANSCODING_BAD_PARAMETER;
    }

    CoInitialize(NULL);

    for (unsigned int i = 0; i < filepath.size(); i++) {
        if (filepath[i] == '/') {
            filepath[i] = '\\';
        }
    }
    utf8_to_wstring(filepath.c_str(), &tfilepath);

    // Get the width and height of original file
    image = Image::FromFile(tfilepath, FALSE);
    org_width = image->GetWidth();
    org_height = image->GetHeight();
    image->GetRawFormat(&raw_format_guid);
    delete image;

    r1 = (double)org_height / org_width;
    r2 = (double)height / width;

    if (org_width == 0 || org_height == 0) {
        LOG_ERROR("Failed to get original image size, org_width = "FMTu_size_t", org_height = "FMTu_size_t"", org_width, org_height);
        rc = IMAGE_TRANSCODING_FAILED;
        goto failed_to_get_org_img_size;
    }

    // org_width > org_height
    if (r1 < 1) {
        if (r1 <= r2) {
            max_wh_size = width;
        } else {
            max_wh_size = org_width * height / org_height;
        }
    // org_width <= org_height
    } else {
        if (r1 >= r2) {
            max_wh_size = height;
        } else {
            max_wh_size = org_height * width / org_width;
        }
    }

    result = GetScaledBitmap(tfilepath, hbitmap, max_wh_size);
    if (result != S_OK || hbitmap == NULL) {
        LOG_ERROR("Failed to transcode, HRESULT = %d", result);
        rc = IMAGE_TRANSCODING_FAILED;
        goto failed_to_scale;
    }

    if (isWin8() && raw_format_guid != Gdiplus::ImageFormatTIFF) {
        HBITMAP hRotate = NULL;
        HBITMAP hMirror = NULL;
        int orientation = getPhotoOrientation(tfilepath);
        aarot _aarot;
        CImage image;

        LOG_DEBUG("Is win8, need to rotate if orientation is not 0 nor 1.");
        switch (orientation) {
            case 0:
            case 1:
                image.Attach(hbitmap);
                break;
            case 2:
                hMirror = ImageMirror(hbitmap);
                image.Attach(hMirror);
                break;
            case 3:
                hRotate = _aarot.rotate(hbitmap, 180, NULL);
                image.Attach(hRotate);
                break;
            case 4:
                hMirror = ImageMirror(hbitmap);
                hRotate = _aarot.rotate(hMirror, 180, NULL);
                image.Attach(hRotate);
                break;
            case 5:
                hMirror = ImageMirror(hbitmap);
                hRotate = _aarot.rotate(hMirror, 90, NULL);
                image.Attach(hRotate);
                break;
            case 6:
                hRotate = _aarot.rotate(hbitmap, 90, NULL);
                image.Attach(hRotate);
                break;
            case 7:
                hMirror = ImageMirror(hbitmap);
                hRotate = _aarot.rotate(hMirror, -90, NULL);
                image.Attach(hRotate);
                break;
            case 8:
                hRotate = _aarot.rotate(hbitmap, -90, NULL);
                image.Attach(hRotate);
                break;
        }

        hbitmap = image.Detach();
    }

    bitmap = Bitmap::FromHBITMAP(hbitmap, NULL);

    result = CreateStreamOnHGlobal(NULL, VPL_TRUE, (LPSTREAM*)&stream);
    if (result != S_OK) {
        LOG_ERROR("Failed to create stream, HRESULT = %d", result);
        rc = IMAGE_TRANSCODING_FAILED;
        goto failed_to_create_stream;
    }

    switch(type) {
        case ImageType_JPG:
            GetEncoderClsid(ENCODER_CLSID_NAME_JPG, &clsid);
            break;
        case ImageType_PNG:
            GetEncoderClsid(ENCODER_CLSID_NAME_PNG, &clsid);
            break;
        case ImageType_TIFF:
            GetEncoderClsid(ENCODER_CLSID_NAME_TIFF, &clsid);
            break;
        case ImageType_BMP:
            GetEncoderClsid(ENCODER_CLSID_NAME_BMP, &clsid);
            break;
        case ImageType_GIF:
            GetEncoderClsid(ENCODER_CLSID_NAME_GIF, &clsid);
            break;
        case ImageType_Original:
        default:
            // To use the original image type
            if (raw_format_guid == Gdiplus::ImageFormatJPEG) {
                GetEncoderClsid(ENCODER_CLSID_NAME_JPG, &clsid);
            } else if (raw_format_guid == Gdiplus::ImageFormatPNG) {
                GetEncoderClsid(ENCODER_CLSID_NAME_PNG, &clsid);
            } else if (raw_format_guid == Gdiplus::ImageFormatTIFF) {
                GetEncoderClsid(ENCODER_CLSID_NAME_TIFF, &clsid);
            } else if (raw_format_guid == Gdiplus::ImageFormatBMP) {
                GetEncoderClsid(ENCODER_CLSID_NAME_BMP, &clsid);
            } else if (raw_format_guid == Gdiplus::ImageFormatGIF) {
                GetEncoderClsid(ENCODER_CLSID_NAME_GIF, &clsid);
            } else {
                // Unknown original image type.
                LOG_WARN("Unknown original image type, change to use \"image/jpeg\"");
                GetEncoderClsid(ENCODER_CLSID_NAME_JPG, &clsid);
            }
            break;
    }

    // Setup encoder parameters
    EncoderParameters encoderParameters;
    encoderParameters.Count = 1;
    encoderParameters.Parameter[0].Guid = EncoderQuality;
    encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
    encoderParameters.Parameter[0].NumberOfValues = 1;
    encoderParameters.Parameter[0].Value = &quality; // setup compression level

    //  Save the image to the stream
    saveStatus = bitmap->Save(stream, &clsid, &encoderParameters);
    if (saveStatus != Ok) {
        LOG_WARN("Failed to save into stream.");
        rc = IMAGE_TRANSCODING_FAILED;
        goto stream_failed;
    }

    // get the size of the stream
    ULARGE_INTEGER ulnSize;
    LARGE_INTEGER lnOffset;
    lnOffset.QuadPart = 0;
    if (stream->Seek(lnOffset, STREAM_SEEK_END, &ulnSize) != S_OK) {
        LOG_WARN("Failed to seek stream.");
        rc = IMAGE_TRANSCODING_FAILED;
        goto stream_failed;
    }

    // now move the pointer to the begining of the file
    if(stream->Seek(lnOffset, STREAM_SEEK_SET, NULL) != S_OK) {
        LOG_WARN("Failed to seek stream.");
        rc = IMAGE_TRANSCODING_FAILED;
        goto stream_failed;
    }

    out_image_len = (size_t) ulnSize.QuadPart;
    buf = new unsigned char[out_image_len];
    *out_image = buf;
    ULONG ulBytesRead;
    if (stream->Read(buf, out_image_len, &ulBytesRead) != S_OK) {
        LOG_WARN("Failed to read from stream.");
        rc = IMAGE_TRANSCODING_FAILED;
        free(buf);
        *out_image = NULL;
        out_image_len = 0;
    }

 stream_failed:
    stream->Release();
 failed_to_create_stream:
    DeleteObject(hbitmap);
    delete bitmap;
 failed_to_scale:
 failed_to_get_org_img_size:
    free(tfilepath);
    CoUninitialize();
    return rc;
}
Exemple #29
-1
void TabOne::OnBnClickedButton2()
{
	countImage -=1;
	cvSaveImage(savePath,img0[countImage]);
	
	CImage img;
	img.Load(savePath);
	m_PicCtrl.SetBitmap((HBITMAP)img.Detach());
	
	if(countImage<4)
			SetDlgItemTextA(IDC_EDIT1, "Please Click LEFT EYE critical points");
			

	if(countImage>=4&& countImage<8)
			SetDlgItemTextA(IDC_EDIT1, "Please Click RIGHT EYE critical points");
			//MessageBox("Please Click RIGHT EYE critical points!!!!!!", "Click Critical Points Selection",  MB_OK | MB_ICONEXCLAMATION);

		if(countImage<11 && countImage >=8)
			SetDlgItemTextA(IDC_EDIT1, "Please Click NOSE critical points");
			//MessageBox("Please Click NOSE critical points!!!!!!", "Click Critical Points Selection",  MB_OK | MB_ICONEXCLAMATION);

		if(countImage>=11)
			SetDlgItemTextA(IDC_EDIT1, "Please Click MOUTH critical points");
			//MessageBox("Please Click MOUTH critical points!!!!!!", "Click Critical Points Selection",  MB_OK | MB_ICONEXCLAMATION);

	//cvShowImage(name, img0[countImage-1]);
	
}