Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a function that convert pdf to pictures, but the pictures will be blurred #13

Open
NullYing opened this issue Dec 3, 2020 · 1 comment

Comments

@NullYing
Copy link

NullYing commented Dec 3, 2020

提供一个可以转出图片的函数,但是转出来的图片会模糊,暂时不知道怎么解决

func (p *Page) Convert2Image() image.Image {
	// Render the PDF file
	width, height := p.Size()
	surface := cairo.NewSurface(cairo.FORMAT_ARGB32, int(width), int(height))

	pattern := cairo.NewPatternForSurface(surface)
	pattern.SetFilter(cairo.CAIRO_FILTER_NEAREST)
	defer pattern.Destroy()

	_, drawcontext :=  surface.Native()
	surface.SetSource(pattern)

	C.poppler_page_render_for_printing(p.p, (*C.cairo_t)(unsafe.Pointer(drawcontext)))

	defer surface.Finish()
	return surface.GetImage()
}
@jilieryuyi
Copy link

提供一个可以转出图片的函数,但是转出来的图片会模糊,暂时不知道怎么解决

func (p *Page) Convert2Image() image.Image {
	// Render the PDF file
	width, height := p.Size()
	surface := cairo.NewSurface(cairo.FORMAT_ARGB32, int(width), int(height))

	pattern := cairo.NewPatternForSurface(surface)
	pattern.SetFilter(cairo.CAIRO_FILTER_NEAREST)
	defer pattern.Destroy()

	_, drawcontext :=  surface.Native()
	surface.SetSource(pattern)

	C.poppler_page_render_for_printing(p.p, (*C.cairo_t)(unsafe.Pointer(drawcontext)))

	defer surface.Finish()
	return surface.GetImage()
}

可以运行,报错
(process:382): GLib-GObject-CRITICAL **: 23:43:30.675: g_object_unref: assertion 'G_IS_OBJECT (object)' failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants