Why new Image failed?
-
<pre lang="c++">
Image* m_pImage;
CString strTempIMGPath = m_strCurrentImagePath;
wchar_t szFile[256] = {0};char \*pStr = strTempIMGPath.GetBuffer(0); int size = MultiByteToWideChar(GetACP(), 0, pStr, -1, NULL, 0); MultiByteToWideChar(GetACP(), 0, pStr, -1, szFile, size); strTempIMGPath.ReleaseBuffer(); if (m\_pImage != NULL) { delete m\_pImage; m\_pImage = NULL; }
<b> m_pImage = new Image(szFile, FALSE);</b>
if(m_pImage->GetLastStatus() == Gdiplus::Status::Ok)
{
...
}After this statement,m_pImage = new Image(szFile, FALSE) the m_pImage is NULL, I do not know why create Image failed, after debug that I find that the szFile is a right PNG image file path. The last code used in a CDialog form, I use the CDialog::DoModel() to show this dialog in the CMyApp::InitInstance() I do not know whether I use this class Image too early, or I need use some code to initialize the GDI+ library?
-
<pre lang="c++">
Image* m_pImage;
CString strTempIMGPath = m_strCurrentImagePath;
wchar_t szFile[256] = {0};char \*pStr = strTempIMGPath.GetBuffer(0); int size = MultiByteToWideChar(GetACP(), 0, pStr, -1, NULL, 0); MultiByteToWideChar(GetACP(), 0, pStr, -1, szFile, size); strTempIMGPath.ReleaseBuffer(); if (m\_pImage != NULL) { delete m\_pImage; m\_pImage = NULL; }
<b> m_pImage = new Image(szFile, FALSE);</b>
if(m_pImage->GetLastStatus() == Gdiplus::Status::Ok)
{
...
}After this statement,m_pImage = new Image(szFile, FALSE) the m_pImage is NULL, I do not know why create Image failed, after debug that I find that the szFile is a right PNG image file path. The last code used in a CDialog form, I use the CDialog::DoModel() to show this dialog in the CMyApp::InitInstance() I do not know whether I use this class Image too early, or I need use some code to initialize the GDI+ library?
-
<pre lang="c++">
Image* m_pImage;
CString strTempIMGPath = m_strCurrentImagePath;
wchar_t szFile[256] = {0};char \*pStr = strTempIMGPath.GetBuffer(0); int size = MultiByteToWideChar(GetACP(), 0, pStr, -1, NULL, 0); MultiByteToWideChar(GetACP(), 0, pStr, -1, szFile, size); strTempIMGPath.ReleaseBuffer(); if (m\_pImage != NULL) { delete m\_pImage; m\_pImage = NULL; }
<b> m_pImage = new Image(szFile, FALSE);</b>
if(m_pImage->GetLastStatus() == Gdiplus::Status::Ok)
{
...
}After this statement,m_pImage = new Image(szFile, FALSE) the m_pImage is NULL, I do not know why create Image failed, after debug that I find that the szFile is a right PNG image file path. The last code used in a CDialog form, I use the CDialog::DoModel() to show this dialog in the CMyApp::InitInstance() I do not know whether I use this class Image too early, or I need use some code to initialize the GDI+ library?
// Used for GDI+ initialisation.
ULONG_PTR m_gdiplusToken;// Initialization of GDI+ library.
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);The GdiplusStartup function initializes GDI+. Call GdiplusStartup before making any other GDI+ calls, and call GdiplusShutdown when you have finished using GDI+.
-
// Used for GDI+ initialisation.
ULONG_PTR m_gdiplusToken;// Initialization of GDI+ library.
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);The GdiplusStartup function initializes GDI+. Call GdiplusStartup before making any other GDI+ calls, and call GdiplusShutdown when you have finished using GDI+.