Does D3DXLoadSurfaceFromFileInMemory function really support png
Hi , guys,
In my project, I will use file buffer to create texture instead of local
file. The buffer is downloaded through http. I want to avoid save the buffer
to local file then create texture .So I try to use
D3DXLoadSurfaceFromFileInMemory() function to create surface. It works fine
if the buffer is bmp file buffer. All other file type will return
failed,D3DXERR_INVALIDDATA.
In MSDN ,This function supports the following file formats: .bmp, .dds,
..dib, .jpg, .png, and .tga.
Did I do anything wrong? Thank you for any suggestion and help!
Bravew
Here is the code:
//testing code , simulating get image buffer from internet
//char fileName[] = "c:\\image\\a.bmp";
char fileName[] = "c:\\image\\transparent.png"; //error
struct __stat64 buf;
int fd, result;
fd = _open( fileName, _O_RDONLY );
result = _fstat64( fd, &buf );
BYTE * buffer = new BYTE [ buf.st_size ];
FILE *fp = 0;
fp = fopen(fileName,"r");
int bytes;
bytes = fread(buffer, 1, buf.st_size, fp);
mpNormTex->GetSurfaceLevel(levelMipMap, &surface);
// get D3DXIMAGE_INFO first
D3DXIMAGE_INFO imageInfo;
hr = D3DXGetImageInfoFromFileInMemory(buffer,size,&imageInfo);
// Here is the problem, it will return D3DXERR_INVALIDDATA for not bmp file
hr = D3DXLoadSurfaceFromFileInMemory (surface, NULL, NULL, buffer,
buf.st_size, NULL, D3DX_FILTER_NONE, 0, &imageInfo) ;
_close( fd );
fclose(fp);
date: Sun, 26 Mar 2006 15:07:27 -0800
author: Bravew