How to load an image from a BYTE * array using CImage? My workaround so far is simply to create a temporary file, but this operation is very expensive sometimes ... There are probably libraries for this, but I do not want to reference other libraries, all I need is to get the image size and display it efficiently it on the screen, and CImage is all I need for this ...
p-> pbData is an BYTE * array, and p-> dwDataLen is a DWORD that contains the size of the array
My code is:
ATL::CAtlTemporaryFile TempFile;
TempFile.Create(NULL, GENERIC_WRITE | GENERIC_READ);
TempFile.Write(p->pbData, p->dwDataLen);
TempFile.HandsOff();
ATL::CImage m_image;
m_image.Load(TempFile.TempFileName());
TempFile.Close();
int h = m_image.GetHeight();
int w = m_image.GetWidth();
m_image.Destroy();
m_image.ReleaseGDIPlus();`
source
share