0

我想将 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());
4

1 回答 1

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 ) ;

...

于 2019-12-17T22:14:52.913 回答