Пример #1
0
func (pdf *PDF) LoadRawImageFromFile(
	filename string, width, height uint32, colorSpace ColorSpace,
) (*Image, error) {
	cfilename := C.CString(filename)
	cimage := C.HPDF_LoadRawImageFromFile(
		pdf.doc, cfilename,
		C.HPDF_UINT(width), C.HPDF_UINT(height),
		C.HPDF_ColorSpace(colorSpace),
	)
	C.free(unsafe.Pointer(cfilename))

	if cimage != nil {
		return newImage(cimage, pdf), nil
	} else {
		return nil, pdf.GetLastError()
	}
}
Пример #2
0
func (pdf *PDF) LoadRawImageFromMem(
	mem []byte,
	width uint32,
	height uint32,
	colorSpace ColorSpace,
	bitsPerComponent uint32,
) (*Image, error) {
	ptr := (*C.HPDF_BYTE)((unsafe.Pointer(&mem[0])))
	cimage := C.HPDF_LoadRawImageFromMem(
		pdf.doc,
		ptr,
		C.HPDF_UINT(width),
		C.HPDF_UINT(height),
		C.HPDF_ColorSpace(colorSpace),
		C.HPDF_UINT(bitsPerComponent),
	)

	if cimage != nil {
		return newImage(cimage, pdf), nil
	} else {
		return nil, pdf.GetLastError()
	}
}