23 : width(0), height(0), format(0), image(0)
35 image =
new(__FILE__,__LINE__) DWORD [pixels];
37 if (
image && pixels) {
38 for (
int i = 0; i < pixels; i++)
55 fopen_s(&f, filename,
"rb");
62 fseek(f, 0, SEEK_END);
64 fseek(f, 0, SEEK_SET);
66 buf =
new(__FILE__,__LINE__) BYTE[len];
69 fread(buf, len, 1, f);
89 hr = D3DXGetImageInfoFromFileInMemory(buf, len, &info);
103 IDirect3DSurface9* surf = 0;
107 hr = dev->CreateOffscreenPlainSurface(
width,
117 hr = D3DXLoadSurfaceFromFileInMemory( surf,
128 D3DLOCKED_RECT locked_rect;
129 hr = surf->LockRect(&locked_rect, NULL, D3DLOCK_READONLY);
135 for (DWORD i = 0; i <
height; i++) {
137 BYTE* src = (BYTE*) locked_rect.pBits + i * locked_rect.Pitch;
139 CopyMemory(dst, src, width *
sizeof(DWORD));
159 bool success =
false;
166 fopen_s(&f, filename,
"wb");
170 IDirect3DSurface9* surf = 0;
173 hr = dev->CreateOffscreenPlainSurface(
width,
182 D3DLOCKED_RECT locked_rect;
183 hr = surf->LockRect(&locked_rect, NULL, 0);
187 for (DWORD i = 0; i <
height; i++) {
189 BYTE* dst = (BYTE*) locked_rect.pBits + i * locked_rect.Pitch;
191 CopyMemory(dst, src, width *
sizeof(DWORD));
196 ID3DXBuffer* buffer = 0;
197 D3DXIMAGE_FILEFORMAT imgfmt = D3DXIFF_PNG;
199 if (strstr(filename,
".jpg") || strstr(filename,
".JPG"))
200 imgfmt = D3DXIFF_JPG;
202 else if (strstr(filename,
".bmp") || strstr(filename,
".BMP"))
203 imgfmt = D3DXIFF_BMP;
205 hr = D3DXSaveSurfaceToFileInMemory(&buffer,
212 fwrite(buffer->GetBufferPointer(), buffer->GetBufferSize(), 1, f);