我正在尝试读取一个文件并创建一个流对象。从这个流对象,我正在创建一个 GDI 图像。我注意到它不起作用,尤其是 if (image && (Ok == image->GetLastStatus())) 返回状态 3 的行,知道是什么问题吗?我正在尝试使用 EMF 文件作为测试:
unsigned char* filebuf;
FILE* fp;
size_t sz;
Image* image = NULL;
Image* thumbnail = NULL;
fp = fopen(filename, "rb"); //Statement 1
if (fp == NULL)
{
printf("\nCan't open file or file doesn't exist.\r\n");
exit(0);
}
fseek(fp, 0L, SEEK_END);
sz = ftell(fp);
fseek(fp, 0L, SEEK_SET);
filebuf = (unsigned char*)malloc(sz);
if (filebuf)
fread(filebuf, sz, 1, fp);
//lets create stream from memory and then we will create image.
IStream* stream = SHCreateMemStream(filebuf, sz);
image = Gdiplus::Image::FromStream(stream);
if (image && (Ok == image->GetLastStatus())) {
//printf("Image loaded\n");
thumbnail = image->GetThumbnailImage(100, 100, NULL, NULL);
if (thumbnail && (Ok == thumbnail->GetLastStatus())) {
//printf("Thumbnail created\n");
}
}
//printf("Done\n");
if (image) delete image;
if (thumbnail) delete thumbnail;
return 0;
它应该创建流对象,然后它应该能够创建图像和缩略图。