static BOOL drawImage(HDC hDC, LPCTSTR lpszFileName) { IImagingFactory* pImageFactory = NULL; BOOL bRet = FALSE; if (SUCCEEDED(CoCreateInstance(CLSID_ImagingFactory, 0, CLSCTX_INPROC_SERVER, IID_IImagingFactory, (void**)&pImageFactory))) { IImage* pImage = NULL; ImageInfo imageInfo; if (SUCCEEDED(pImageFactory->CreateImageFromFile(lpszFileName, &pImage)) && SUCCEEDED(pImage->GetImageInfo(&imageInfo))) { RECT rect = {0, 0, imageInfo.Width, imageInfo.Height}; pImage->Draw(hDC, &rect, 0); pImage->Release(); bRet = TRUE; } pImageFactory->Release(); } return bRet; }
static void DynamicLightParamAssign(const DynamicLightParam& other, DynamicLightParam *self) { IImage *old = self->image; *self = other; self->image->AddRef(); old->Release(); }
virtual void Execute(IRenderer *r){ if(img){ def.image = img; img = NULL; } r->AddLight(def); if(img){ img->Release(); } }
HBITMAP SHLoadImageFile( LPCTSTR pszFileName ) { if ( !pszFileName || !*pszFileName ) return 0; String strFileName = convertToStringA(pszFileName); /*if ( String_endsWith(strFileName, ".bmp") ) { return (HBITMAP)::LoadImage(NULL, pszFileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); }*/ if ( !String_endsWith(strFileName, ".png") && !String_endsWith(strFileName, ".bmp") ) return 0; IImagingFactory *pImgFactory = NULL; IImage *pImage = NULL; //CoInitializeEx(NULL, COINIT_MULTITHREADED); HBITMAP hResult = 0; if (SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IImagingFactory, (void **)&pImgFactory))) { ImageInfo imageInfo; if (SUCCEEDED(pImgFactory->CreateImageFromFile(CA2W(strFileName.c_str()), &pImage)) && SUCCEEDED(pImage->GetImageInfo(&imageInfo))) { CWindowDC dc(getMainWnd()); CDC dcBitmap; dcBitmap.CreateCompatibleDC(dc.m_hDC); hResult = CreateCompatibleBitmap(dc.m_hDC, imageInfo.Width, imageInfo.Height); if (hResult) { HBITMAP hOldBitmap = dcBitmap.SelectBitmap(hResult); //dcBitmap.FillSolidRect( 0,0, imageInfo.Width, imageInfo.Height, RGB(255,255,255)); CRect rc(0, 0, imageInfo.Width, imageInfo.Height); COLORREF clrOld = ::SetBkColor(dcBitmap.m_hDC, RGB(255,255,255)); ::ExtTextOut(dcBitmap.m_hDC, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL); ::SetBkColor(dcBitmap.m_hDC, clrOld); pImage->Draw(dcBitmap.m_hDC, rc, NULL); dcBitmap.SelectBitmap(hOldBitmap); } pImage->Release(); } pImgFactory->Release(); } //CoUninitialize(); return hResult; }
HBITMAP LoadImageThumbnailWithImagingApi(const CString &strFileName, int imgWid, int imgHei) { IImagingFactory *pImgFactory = NULL; IImage *pImage = NULL; IImage *pImageThumb = NULL; CoInitializeEx(NULL, COINIT_MULTITHREADED); HBITMAP hResult = 0; if (SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IImagingFactory, (void **)&pImgFactory))) { ImageInfo imageInfo; if (SUCCEEDED(pImgFactory->CreateImageFromFile(strFileName, &pImage)) && SUCCEEDED(pImage->GetThumbnail(imgWid, imgHei, &pImageThumb)) && SUCCEEDED(pImageThumb->GetImageInfo(&imageInfo))) { CWindowDC dc(0); CDC dcBitmap; dcBitmap.CreateCompatibleDC(&dc); hResult = CreateCompatibleBitmap(dc.GetSafeHdc(), imageInfo.Width, imageInfo.Height); if (hResult) { HGDIOBJ hOldBitmap = dcBitmap.SelectObject(hResult); pImage->Draw(dcBitmap.GetSafeHdc(), CRect(0, 0, imageInfo.Width, imageInfo.Height), NULL); dcBitmap.SelectObject(hOldBitmap); } pImageThumb->Release(); pImage->Release(); } pImgFactory->Release(); } CoUninitialize(); return hResult; }
void ocr(LPCTSTR pszName) { USES_CONVERSION; HRESULT hr = NULL; IDocument *pDoc = NULL; IImages *pImages = NULL; IImage *pImage = NULL; ILayout *pLayout = NULL; IWords *pWords = NULL; IWord *pWord = NULL; IMiRects *pRects = NULL; IMiRect *pRect = NULL; long iCount = 0, wCount = 0, rCount = 0, count = 0; long left, top, right, bottom, minTop = 0, maxBottom = 0, savedMaxBottom = 0; short conf = 0; double tConf = 0.0; CComBSTR bstrName; BSTR bstrText; CString strText; #if _OCR_DEBUG > 0 CString strDebug; strDebug.Format("OCR %s!", pszName); MessageBox(NULL, strDebug, "OCR.DLL", MB_ICONINFORMATION); #endif hr = CoInitialize(0); // hr = CoInitializeEx(pReserved, COINIT_MULTITHREADED); // hr = CoInitializeEx(pReserved, COINIT_APARTMENTTHREADED); #if _OCR_DEBUG > 0 strDebug.Format("CoInitialize result = 0x%08X!", hr); MessageBox(NULL, strDebug, "OCR.DLL", MB_ICONINFORMATION); #endif if (!SUCCEEDED(hr)) return; hr = CoCreateInstance(CLSID_Document, NULL, CLSCTX_INPROC_SERVER, IID_IDocument, (void**) &pDoc); // hr = CoCreateInstance(CLSID_Document, NULL, CLSCTX_INPROC_SERVER, IID_IDocument, (void**) &pDisp); // hr = pDisp->QueryInterface(IID_IDocument, (void**) &pDoc); // hr = pDoc.CoCreateInstance(CLSID_Document); // hr = CoGetClassObject(CLSID_Document, CLSCTX_INPROC_SERVER, NULL, IID_IDocument, (void**) &pDoc); #if _OCR_DEBUG > 0 strDebug.Format("CoCreateInstance result = 0x%08X!", hr); MessageBox(NULL, strDebug, "OCR.DLL", MB_ICONINFORMATION); #endif if (!SUCCEEDED(hr)) return; bstrName = pszName; hr = pDoc->Create(bstrName); #if _OCR_DEBUG > 0 strDebug.Format("IDocument created, result = 0x%08X!", hr); MessageBox(NULL, strDebug, "OCR.DLL", MB_ICONINFORMATION); #endif if (!SUCCEEDED(hr)) return; hr = pDoc->OCR(miLANG_CHINESE_SIMPLIFIED, FALSE, FALSE); #if _OCR_DEBUG > 0 strDebug.Format("IDocument OCR result = 0x%08X!", hr); MessageBox(NULL, strDebug, "OCR.DLL", MB_ICONINFORMATION); #endif if (!SUCCEEDED(hr)) return; pDoc->get_Images(&pImages); pImages->get_Count(&iCount); for (long i = 0; i < iCount; i++ ) { pImages->get_Item(i, (IDispatch**)&pImage); pImage->get_Layout(&pLayout); pLayout->get_Words(&pWords); pWords->get_Count(&wCount); for (long j = 0; j < wCount; j++) { pWords->get_Item(j, (IDispatch**)&pWord); pWord->get_Rects(&pRects); pRects->get_Count(&rCount); minTop = maxBottom = 0; for (long k = 0; k < rCount; k++) { pRects->get_Item(k, (IDispatch**)&pRect); pRect->get_Left(&left); pRect->get_Top(&top); pRect->get_Right(&right); pRect->get_Bottom(&bottom); if (minTop == 0) minTop = top; if (minTop > top) minTop = top; if (maxBottom < bottom) maxBottom = bottom; if (pRect) pRect->Release(); } if (pRects) pRects->Release(); if (savedMaxBottom == 0) savedMaxBottom = maxBottom; if (minTop >= savedMaxBottom) { tConf /= count; savedMaxBottom = maxBottom; strText = ""; tConf = 0.0; count = 0; } pWord->get_Text(&bstrText); pWord->get_RecognitionConfidence(&conf); tConf += conf; count++; strText += bstrText ? OLE2CT(bstrText) : _T(""); if (pWord) pWord->Release(); } if (strText.GetLength() > 0) { tConf /= count; strText = ""; tConf = 0.0; count = 0; } if (pWords) pWords->Release(); if (pLayout) pLayout->Release(); if (pImage) pImage->Release(); } if (pImages) pImages->Release(); pDoc->Close(0); pDoc->Release(); CoUninitialize(); return pItems; }
void DrawingImageImpl::init(const char* path, void const *p, int size, WMBitmap* bitmap, bool useAlpha) { mID = ++ourDrawingImageID; RHO_MAP_TRACE1("DrawingImage create with ID = %d", mID); #if defined(_WIN32_WCE) IImagingFactory *pImgFactory = NULL; IImage *pImage = NULL; mWidth = 0; mHeight = 0; mBitmap = NULL; if (bitmap != NULL) { mBitmap = bitmap; mBitmap->addRef(); mWidth = bitmap->width(); mHeight = bitmap->height(); return; } HRESULT co_init_result = CoInitializeEx(NULL, 0/*COINIT_APARTMENTTHREADED*/); if ( (co_init_result == S_OK) || (co_init_result == S_FALSE) ) { msg_out("CoInitializeEx OK"); if (SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IImagingFactory, (void **)&pImgFactory))) { HRESULT res = 0; if (p != NULL) { // from buf res = pImgFactory->CreateImageFromBuffer( p, size, BufferDisposalFlagNone, &pImage); } else { // from file msg_out("Create Image Factory OK"); wchar_t wc_filename[2048]; mbstowcs(wc_filename, path, 2048); res = pImgFactory->CreateImageFromFile( wc_filename, &pImage); } if (SUCCEEDED(res)) { IImage* mimage = pImage; ImageInfo imgInfo; mimage->GetImageInfo(&imgInfo); mWidth = imgInfo.Width; mHeight = imgInfo.Height; RHO_MAP_TRACE2("Drawing Image was created with WIDTH = %d, HEIGHT = %d", mWidth, mHeight); mBitmap = new WMBitmap(mimage, useAlpha); mimage->Release(); } else { err_out("Image not created !"); } pImgFactory->Release(); } else { err_out("ImageFactory not created !"); } CoUninitialize(); } else { err_out("CoInitializeEx not initialized !"); } #endif //#if defined(_WIN32_WCE) }
virtual void Execute(IRenderer *r){ r->DrawImage(img, outTopLeft, outTopRight, outBottomLeft, inRect); img->Release(); img = NULL; }
virtual void Execute(IRenderer *r){ r->AddLongSprite(img, p1, p2, radius); img->Release(); img = NULL; }
virtual void Execute(IRenderer *r){ r->AddSprite(img, center, radius, rotation); img->Release(); img = NULL; }