#14 LoadPNGImageFromMemory

open
nobody
None
5
2009-04-16
2009-04-16
No

Instead of loading the PNG from a file, here's a method to load from a memory buffer. This goes in hpdf_doc_png.c. Don't forget to add the function declaration to hpdf.h.

I believe I had to change the function HPDF_MemStream_WriteFunc to only accept a const HPDF_BYTE *ptr.

HPDF_EXPORT(HPDF_Image)
HPDF_LoadPngImageFromMemory (HPDF_Doc pdf,
const HPDF_BYTE* pMemoryPNG,
HPDF_UINT memSizePNG)
{
HPDF_Stream imagedata;
HPDF_Image image;

HPDF_PTRACE ((" HPDF_LoadPngImageFromMemory\n"));

if (!HPDF_HasDoc (pdf) || (pMemoryPNG == NULL) || (memSizePNG==0))
return NULL;

/* create the memory stream */
imagedata = HPDF_MemStream_New(pdf->mmgr, memSizePNG);

/* copy from the external buffer into the stream */
HPDF_MemStream_WriteFunc(imagedata, pMemoryPNG, memSizePNG);

if (HPDF_Stream_Validate (imagedata))
image = LoadPngImageFromStream (pdf, imagedata, HPDF_FALSE);
else
image = NULL;

/* destroy memory stream */
if (imagedata)
HPDF_MemStream_FreeData (imagedata);

if (!image)
HPDF_CheckError (&pdf->error);

return image;
}

Discussion

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks