|
- bool CGPSGuidsDlg::InitMap(const WCHAR* fileName)
- {
- IImagingFactory* pImagingFactory;
- IImage* pImage;
- ImageInfo imageInfo;
- HBITMAP hBitmap;
- CDC* hDC = GetDC();
- ASSERT(hDC != NULL);
- HRESULT hr;
- bool rs = false;
-
- if (SUCCEEDED(hr = CoInitializeEx(NULL, COINIT_MULTITHREADED)))
- {
- if (SUCCEEDED(hr = CoCreateInstance(CLSID_ImagingFactory,NULL,
- CLSCTX_INPROC_SERVER,
- IID_IImagingFactory,
- (void**)&pImagingFactory)))
- {
- if (SUCCEEDED(hr = pImagingFactory->CreateImageFromFile(fileName, &pImage)))
- {
- pImage->GetImageInfo(&imageInfo);
- hBitmap = CreateCompatibleBitmap(hDC->GetSafeHdc(), imageInfo.Width, imageInfo.Height); //这里申请了很大内存并没有释放掉...
- /*hDC->DeleteDC()*/
- //DeleteCompatibleBitmap(hBitmap);
- DeleteDC(m_hMemDC);
- m_hMemDC = CreateCompatibleDC(hDC->GetSafeHdc());
- SelectObject(m_hMemDC, hBitmap);
- m_rcMem.left = 0;
- m_rcMem.top = 0;
- m_rcMem.right = imageInfo.Width;
- m_rcMem.bottom = imageInfo.Height;
-
- //draw the img to mem
- pImage->Draw(m_hMemDC, &m_rcMem, NULL);
- //大地图和小地图之间的比例
- m_nImageWidth = imageInfo.Width;
- m_nImageHeight = imageInfo.Height;
- rs = true;
- }
- }
- }
- DeleteObject(&hr);
- DeleteObject(hBitmap);
- DeleteObject(&imageInfo);
- if (pImagingFactory != NULL)
- {
- pImagingFactory->Release();
- pImagingFactory = NULL;
- }
-
- if (pImage != NULL)
- {
- pImage->Release();
- pImage = NULL;
- }
-
- CoUninitialize();
- if (hDC != NULL)
- {
- ReleaseDC(hDC);
- DeleteObject(hDC);
- }
- return rs;
- }
复制代码
|
|