我想从文件中将PNG图像加载到缓冲区,然后再加载到HPDF_Image,但是我无法使用HPDF_LoadPngImageFromMem从缓冲区中获取图像,因为它会返回HPDF_INVALID_PNG_IMAGE。
// Getting size
std::ifstream t("3CM//A_3cm2.png");
t.seekg(0, std::ios::end);
size_t size = t.tellg();
// Filling buffer
std::string buffer(size, ' ');
t.seekg(0);
t.read(&buffer[0], size);
// Loading Image from buffer
HPDF_Image image = HPDF_LoadPngImageFromMem(pdf, (HPDF_BYTE*) buffer.c_str(), buffer.size());
答案 0 :(得分:1)
为什么要先将图像加载到内存中? 这段代码工作正常
HPDF_Doc Pdf = HPDF_New ( error_handler , NULL ) ;
HPDF_Page Page = HPDF_AddPage ( Pdf ) ;
HPDF_Image MyImage = HPDF_LoadPngImageFromFile ( Pdf ,"3CM//A_3cm2.png" ) ;
HPDF_REAL Width = HPDF_Image_GetWidth ( MyImage ) ;
HPDF_REAL Height = HPDF_Image_GetHeight ( MyImage ) ;
HPDF_Page_DrawImage ( Page , MyImage , x , y , Width , Height ) ;
...