本文主要是介绍mfc Png转IStream,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
BYTE *pData = NULL;DWORD dwReadedSize = 0; //保存实际读取的文件大小{HANDLE hFile = CreateFile(wcBkImageOfPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);//从指定的路径szImagePath中读取文件句柄if (hFile != INVALID_HANDLE_VALUE){DWORD dwFileSize = GetFileSize(hFile, NULL);//获得图片文件的大小,用来分配全局内存while (!pData){pData = new BYTE[dwFileSize];memset(pData, 0, dwFileSize);}ReadFile(hFile, pData, dwFileSize, &dwReadedSize, NULL); //读取图片到全局内存当中CloseHandle(hFile); //关闭文件句柄}}if (pData){HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwReadedSize);IStream *pStream = NULL;HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);pStream->Write(pData, dwReadedSize, NULL);Image m_BKImage(pStream);graphics.DrawImage(&m_BKImage, 0, 0, m_BKImage.GetWidth(), m_BKImage.GetHeight());pStream->Release();GlobalFree(hGlobal);delete[] pData;pData = NULL;}
现在就可以将Png正确加载了
这篇关于mfc Png转IStream的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!