[Gambas-user] How to insert a .png file into a CairoPdfSurface (gb.cairo)

Tobias Boege taboege at ...626...
Sat Aug 24 10:54:35 CEST 2013


On Sat, 24 Aug 2013, Willy Raets wrote:
> On Sat, 2013-08-24 at 03:19 +0200, Willy Raets wrote:
> > Hi All,
> > 
> > Been struggling with inserting an existing .png file onto a
> > CairoPdfSurface (gb.cairo).
> > 
> > Done some extensive reading in the documentation but do not seem to find
> > a method get the job done. Is this not possible or am I misunderstanding
> > the documentation?
> > 
> > Piece of the code of the project:
> > 
> > Public Sub MakePdf()
> >   
> >   Dim hPdfProjectFile As CairoPdfSurface
> >   Dim sPdfPath, sPicPath As String
> >   Dim iX, iY As Float
> >   sPicPath = User.Home & "/MyFolder/mypicture.png"
> >   sPdfPath = User.Home & "/MyFolder/project.pdf"
> >   hPdfProjectFile = New CairoPdfSurface(sPdfPath, 210, 297) 
> >   Cairo.Begin(hPdfProjectFile)
> >   '--Draw title --
> >   iY = 250
> >   '-- Some code to determine X co??rdinate iX --
> >   ...
> >   ...
> >   Cairo.Font.Bold = True
> >   Cairo.Font.Size = 18
> >   Cairo.MoveTo(iX, iY)
> >   Cairo.DrawText(Start.ProjectLoadedTitle)
> >   Cairo.Font.Bold = False
> >   '
> >   '--Draw project logo --
> >   iY = 285
> >   ...                   '<== stuck right here!! 
> >   '
> >   '--Draw Document Version--
> >   iY = 500
> >   ...
> >   ...
> >   Cairo.End
> > 
> > End
> > 
> > Anyone any ideas, suggestions, links?
> > 
> 
> Just to clarify, I need the .png in sPicPath = User.Home &
> "/MyFolder/mypicture.png" do be drawn underneath the Title at 
> section '--Draw project logo --
> 

Maybe you could (ab)use Cairo.ImagePattern()? Load the image, call that
method and assign the result to Cairo.Source. Cairo.Paint() then does the
job.

I don't know Cairo but this seems like how it's done here[0]. It works in my
test case.

Regards,
Tobi

[0] http://zetcode.com/gfx/cairo/cairoimages/




More information about the User mailing list